Common Linux Commands
This is a collection of common Linux commands that I use on a regular basis.
ls - List Directory Contents
The ls command lists the contents of a directory.
$ ls
Options
- -a - Show hidden files
- -l - Show long listing format
- -h - Show human-readable file sizes
- -r - Reverse sort order
- -S - Sort by file size
- -t - Sort by modification time
cd - Change Directory
The cd command changes the current working directory.
$ cd /path/to/directory
Options
- - - Change to the previous directory
- ~ - Change to the home directory
- . - Change to the current directory
- .. - Change to the parent directory
pwd - Print Working Directory
The pwd command prints the current working directory.
$ pwd
mkdir - Make Directory
The mkdir command creates a new directory.
$ mkdir /path/to/directory
rm - Remove
The rm command removes files and directories.
$ rm /path/to/file$ rm -r /path/to/directory
Options
- -f - Force removal of files without prompting for confirmation
- -i - Prompt for confirmation before removing files
- -r - Recursively remove directories and their contents
- -v - Print the name of each file before removing it
cp - Copy
The cp command copies files and directories.
$ cp /path/to/file /path/to/destination$ cp -r /path/to/directory /path/to/destination
Options
mv - Move
The mv command moves files and directories.
$ mv /path/to/file /path/to/destination$ mv /path/to/directory /path/to/destination
cat - Concatenate
The cat command prints the contents of a file to the terminal.
$ cat /path/to/file
less - Less
The less command prints the contents of a file to the terminal, but it allows you to scroll through the file.
$ less /path/to/file
grep - Global Regular Expression Print
The grep command searches for a pattern in a file.
$ grep pattern /path/to/file
chmod - Change Mode
The chmod command changes the permissions of a file or directory.
$ chmod 755 /path/to/file
chown - Change Owner
The chown command changes the owner of a file or directory.
$ chown user:group /path/to/file