File and Directory Commands
List all files in working directory:
ls -l
ls -al
Display the present working directory:
pwd
Display directory tree:
tree
Create a directory
mkdir directory_name
Create a recursive directory structure:
mkdir -p directory_name/subdir_name/test
Create an empty file:
touch filename
Create symbolic link:
ln -s /path/to/filename symlink_name
Remove file:
rm file
rm -f file # force removal of file without prompting for confirmation
Remove symlink:
unlink /pat/to/symlink_name
Remove the directory and its contents recursively:
rm -r directory_name
rm -rf directory_name
Copy files or/and directories:
cp original_file copy_file # copy original_file to copy_file
cp -r original_dir copy_dir # copy original_dir to copy_dir recursively
cp -pr original_dir copy_dir # copy original_dir to copy_dir recursively and keep permissions
Move or rename files/directories:
mv object object_moved
View the contents of file:
cat filename
Browse through a text file
less filename.log
Display the first 10 lines of file:
head filename.log
Display the last 10 lines of file:
tail filename.log
Display the last 10 lines of file and watch file content changes:
tail -f filename.log