Cheat Sheet for Linux Everyday Commands - 1

Cheat Sheet for Linux Everyday Commands - 1

Commands to working with the directories

In this post we will be covering the basic commands used for browsing through the directories and working with the files placed in the directory.

Command to know the current working directory or path

pwd

Going to the active user's home directory, use any of the following command

cd
cd ~

Creating the directory named "test" in the current working directory

mkdir test

Moving to the directory named "test" just created in the current working directory

cd test

Going back to one level up from the current working directory

cd ..

Going to the specific path starting from the root path aka absolute path "/home/username/test"

cd /home/username/test

Moving to the root directory from the current working directory

cd /

Going back to the previous directory

cd -

Creating a directory named "name" and then renaming it to "new-name"

mkdir name
mv name new-name

Removing the directory named "new-name"

rm -rf new-name

Creating all the sub-directories in the path "dir/dir1/dir2/dir3"

mkdir -p dir/dir1/dir2/dir3

Removing all the sub-directories in the path "dir/dir1/dir2/dir3"

rm -rf dir

Commands for working with the files

Listing all the files and sub directories in the current directory

ls

Listing all the files matching a pattern in the current directory

ls test*.txt

Listing all the files and sub directories including the hidden files also in the current directory

ls -a

Listing all the files in the current directory and in all the sub directories

ls -R

Listing all the files and sub directories sorted by time in ascending order

ls -t

Listing all the files and sub directories sorted by time in descending order

ls -tr

Listing all the files with the detailed information like rights, owner, size, last modified time, name

ls -l

Displaying the contents within a file named "test.txt"

cat test.txt

Copying the contents of a file named "test.txt" to a new file named "new.txt"

cp test.txt new.txt
cat test.txt > new.txt

Creating a new empty file named "new.txt"

> new.txt
touch new.txt

Renaming a file named "test.txt" to "newest.txt"

mv test.txt newest.txt

Deleting a fie named "test.txt"

rm test.txt