The most important Linux commands you need daily

Use this guide to most important Linux commands, Utilities, and tools for beginners, enterprise administrators, and managers.

Directory Operations:

Command Description
pwd Show current directory
cd dir Change to directory dir
mkdir dir Create a new directory dir
rmdir dir Delete directory dir
ls dir List Contents directory dir

Example:

Special Directories:

Command Description
. Current Directory
.. Up a Directory
~ Home Directory
/ Root Directory
Previous Directory

Example:

ls Options:

Syntax:

Command Description
-a All inc. hidden file
-l Long Format
-i List file’s inode index number
-t Sort by time & date
-d List directories  with ‘ */’ [eg1. ls -d */ ][eg2. ls -d $PWD/* ]
-s List file size
-S Sort by time
-r Reverse order
-R Recursive
-X Sort by extension name

Example:

File Operations:

Command Descriptions
touch file Create a new file
cp file1 file2 Copy file1 to file2
mv file1 file2 Move file1 to file2
rm file Delete a file
cat file Display content of a file
cat file1 file2 Cancatenate files
less file Display file (paginated), q to quit
head file Show first 10 lines
tail file Show last 10 lines [-n N →N lines; -f → Continuos update]

File Searching:

Command Descriptions
grep pattern file Searching for a line with a pattern in a file
grep -v Inverted search
grep -r Recursive search
grep -e pattern -e pattern Multiple patterns
locate file Quick search for a file
which cmd Find locations of binary
find dir -name pattern Find a file with a pattern in dir

Example:

Standard IO Streams:

Command Descriptions
stdin Input typed on the command line
stdout Output on the screen
stderr Errors output on the screen
echo string Write a string to stdout

Example:

Redirection:

Command Descriptions
cmd > file Output of cmd to file
cmd < file file used as input to cmd
cmd >> file Append output to file
cmd 2> file Write errors to file
cmd &> file Errors and stdout to file

Pipe Multiple Commands

Command Descriptions
cmd1 | cmd2 Stdout of cmd1 is used as input to cmd2
cmd1 | &cmd2 Stderr of cmd1 is used as input to cmd2
cmdpart1 \ cmdpart2 Continue command on next line
cmd1; cmd2 Execute cmd1 then cmd2

Processes:

Command Descriptions
ps Show processes of user
ps -e Show all processes
ps -fA Show all processes in detail
top Show all processes in real-time
cmd & Run command in the background
Ctrl-c Stop (kill) currently active process
Ctrl-z Suspend currently active process
bg Place suspended process in a background
fg Bring background process to foreground
kill pid Kill process with process id PID
Kill -9 pid Kill process PID (ungraceful)

Bash Shortcuts:

Command Descriptions
Ctrl-k Cut line of text
Ctrl-y Past line of text
Ctrl-e Go to end of line
Ctrl-a Go to start of line
TAB Autocomplete command/file
TAB-TAB Show list of possible autocompletes
up arrow Scroll previous commands
down arrow Scroll previous commands
histrory List recent commands
!! Repeat the last command
!N Execute command N from history
!abc:p Print the last command starting with abc
!abc Execute the last command starting with abc

Text file operation:

Command Descriptions
wc Line, word and character count
sort file Sort file, line by line
uniq file Display only unique lines of a file
sed ‘s/abc/def/g’ file Replace all occurrence of abc with def, out to stdout
cut -d “ “ -f N file Display field N of space delimited file
cut -d “,” -f M-N file Display field M-N of a comma delimited file

Tar Command:

Command Descriptions
-c Creates a new .tar archive file.
-x To untar or extract a tar file
-v Verbosely show the .tar file progress.
-f File name type of the archive file.
-z compressed gzip archive file
-r To add files or directories to existing tar archive file
-j To create a highly compressed tar file
-C untar in a different directory
-t viewing content of archive file
-W Verify an archive file

Example:

How to create a tar.gz file

To create a tar.gz archive from a given folder you can use the following command

How to extract a tar.gz file

To extract a tar.gz compressed archive you can use the following command

How to extract specific file(s) from tar.gz

Proper file Permissions for WordPress

Three-digit permissions specified in octal

octal-three-digit-permissions

How to find recently modified files

see all files that were modified during the last 2 days

How can I monitor the progress of an import of a large .sql file?

If you’re just importing from a dump file from the CLI on *nix, e.g.

then first install pipe viewer on your OS then try something like this:

How to convert ppk file from pem file?

Make sure puttygen installed on your computer. If it is not installed, type the below command,

How to download YouTube Playlist

The program ‘youtube-dl‘ is currently not installed. You can install it by typing:

Vijayan J

Thanks for stopping by guys! I'm Vijayan and Techpulse is my beloved brainchild. Currently working as a PHP developer in a digital marketing start-up, I'm overly passionate about not just learning new things but also putting those into practice. I swear by a quote I once came across... 'What separates successful people from unsuccessful people is the former's ability to execute'. Feel free to reach out to me if you have any questions, suggestions or feedback. Hoping to see more of you here!