Some Important Commands Used In Linux/Unix

Command-line interface(CLI) is a way that allows users to interact with computer programs through commands. A user issues commands to a program which gets interpreted by a command-line interpreter. Most operating system implements CLI in the form of shells that are used for interactive access of the various services or functions of the operating system. CLI has its own benefits over a graphical user interface(GUI). The command-line interface is more efficient than a GUI. A program can be accessed through CLI, which is not accessible on GUI. So in this article we are going to discuss some important commands that are used in Linux/Unix terminal frequently.

File commands –

lsList files and directories under the current working directory
pwdShow the path of the current working directory
mkdir dir(s)Make a directory with name dir
cd dirChange directory to dir
cdChange the current directory to home directory
rm -r dir(s)Remove or delete the directory dir
rm -rf dir(s)Delete the directory dir forcefully
touch file(s)Create a file
rm file(s)Delete the file
rm -f file(s)Delete the file forcefully
cat >filePlace the standard input into the file
cp file1 file2Copy the content of file1 to file2
cp -r dir1 dir2Copy the directory dir1 to dir2
mv file_or_directory dirMove a file or directory to directory dir

System info commands –

dateShow the current date and time
calShow the month’s calendar
uptimeShow the current uptime(total time of the current session since you log in)
wDisplay who is online
whoamiDisplay who are you logged in as
uname -aDisplay the kernel information
finger user_nameDisplay about the user
man commandDisplay the manual for the given command
dfShow the disk usage and other related information
duShow directory space usage
freeShow the physical memory and swap usage
cat /proc/cpuinfoDisplay Cpu information
cat /proc/meminfoDisplay Memory information

File/directory searching commands –

grep patternSearch for patterns in a file
grep -r pattern dirSearch recursively for a pattern in dir
command | grep patternSearch pattern in the output of a command
locate fileDisplay the path of the file with other file having a similar name
find .-name filenameSearches in the current directory and below it for files and directories with the names starting with filename
pgrep patternSearches for all the named processes, that matches with the pattern and by default, it returns their process ID

Commands used in process management –

psDisplay the current working process
topDisplay the all running process with resource usage
kill pidKill the process with given process ID
killall -9 nameIf more than one process runs with that name, all of them will be killed
pkill patternKill the multiple process matches with pattern
bgResume a stopped job in the background
fgResume a stopped job in the foreground

Detailed use of process management commands with examples are given in a separate article. You should read process management in Linux/Unix.

File permission commands –

chmod octal file -Change the permission of file to octal, which can be found separately for user, group, world by adding, 4-read(r), 2-write(w), 1-execute(x). For detailed use of file permission commands, you should read this article file ownership and permissions in Linux/Unix.

Network commands –

ping hostPing the given host and output the result
whois domainDisplay the information about domain and its owner
dig domainDisplay DNS information for a domain
dig -x hostReverse lookup host
wget fileDownload file
wget -c fileContinue a stopped download

Compression commands –

tar cf file.tar file(s)Create tar named file.tar containing file
tar xf file.tarExtract the files from file.tar
tar czf file.tar.gz file(s)Create a tar with gzip compression
tar xzf file.tar.gzExtract a tar using Gzip
tar cjf file.tar.bz2 file(s)Create tar with Bzip2 compression
tar xjf file.tar.bz2Extract a tar using Bzip2
gzip fileCompress file and rename it to file.gz
gzip -d file.gzDecompress file.gz back to file


Shortcuts used in Linux/Unix terminal –

ctrl+cHalts the current command
ctrl+zSuspend the current command and can be resumed using fg or bg
ctrl+dLogout the current session
ctrl+wErases one word in the line
ctrl+uErases the whole line
ctrl+rType to bring up whole command or reverse search
!!Repeat the last command
exitLogout the current session


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.