Linux Commands

Commands Description
ls To list down all the contents of directory
cd To change the directory
cd /bin/ Change current directory to bin directory
cd ~ The tilde (~) sign signifies the user’s home dir – change dir to home directory
cd .. It changes directory one level up
mkdir To create a directory
pwd It display current directory path
cat <filename> Command to print all the contents of provided filename on the screen
cp It copies the file or directory
cp /home/dw /home/linux It copies the /home/dw/ directory to /home/linux/ directory
mv mv move command is used to move files and directories
mv /home/dw/info.txt /newDirectoryName/ It moves the file info.txt to the /newDirectoryName/ directory. You can also use this command to move the entire directory to another Directory
rm rm command is used to remove files and directories.
rm info.txt This command will remove the file info.txt
find find command perform search of file
find / -name “linux*” The find command is a powerful tool that you can use when searching using the command line. The command here will search for any file or directory with a name that starts with linux
uname -a This command displays information about the machine, the processor architecture, and the operating system details.
lscpu This command returns more information about the system such as the number of CPUs and the CPU speed
cat /proc/cpuinfo This is a file that contains more information than the one displayed using the lscpu command
df -h This command displays the disk space usage in all of the mounted devices. The -h option presents the results in a human readable output, using G for gigabytes or M for megabytes sizes
du ~/Downloads This command displays all the files inside the specified directory and their corresponding file sizes. You can also specify a filename
du ~/Downloads -sh The –s option provides the total file size of the specified directory and -h makes it human readable form
Keys Description Example
info Shows online information about a command $ info uname
man Shows details (manual) of a command $ man uname
whatis Shows a short description of a specific keyword $ whatis uname
type Shows the location of a command file $ type uname
alias Assign a command alias – especially useful for long commands $ alias t=type $ t uname $ alias
unalias Remove command alias $ unalias t
pwd Displays the current directory $ pwd
ln Create links to files and directories $ ln -s [file] [soft-link-to-file] $ ln -s info.txt newinfo.txt
touch To trigger a file stamp update for a file $ touch info.txt
find Search for a file based on the name $ find [dir-path] -name [filename] $ find . -name info.jpeg
whereis Search for executable files $ whereis uname
which Search for files in the directories part of the PATH variable $ which uname
dd Copy lines of data $ dd conv=ucase Type Hello world ctrl+d $ echo “hello world > info.txt $ dd if=info.txt of=newinfo.txt conv=ucase $ cat newinfo.txt
diff Display the results of comparing two files $ echo “hello world > info.txt $ echo “hello world > info1.txt $ diff info.txt info1.txt -s $ echo “hello world123 > newinfo.txt $ diff info.txt newinfo.txt -s
more Show a text file one page at a time – display can only go forward $ ls -R > info.txt $ more info.txt $ ls -R | more
less Show a text file one page at a time – display can only go forward and backwards $ less info.txt $ ls -R | less
wc Display the count of the number of characters, words, and lines in a file $ wc info.txt
cut Get sections of text in a file $ cut -b 1 info.txt $ cut -b 1-3 info.txt $ cut -b 1,3 info.txt
grep Display results of finding expressions in a file $ cat info.txt | grep Desktop $ cat info.txt | grep -i desktop $ grep -i “desktop” info.txt
sed Perform editing commands, then copy to a standard output First occurance in every line will be changed $ dw’s/Desktop/Dashboard/’ info.txt 2nd occurance in every line will be changed $ dw ‘s/Desktop/Dashboard/2’ info.txt All occurances will be changed $ dw ‘s/Desktop/Dashboard/g’ info.txt
split Specify a size to break a file into $ split info.txt $ ls $ rm x* -l100 is 100 lines per file $ split -l100 info.txt $ ls
sort Arrange the lines in a file $ sort info.txt
uniq Keep unique lines in a file and delete duplicates $ echo “Hey Hi Hello Commands Linux Irc” > info.txt $ cat info.txt $ uniq info.txt $ uniq info.txt -c $ uniq info.txt -d
tar Archive files with one or more directories Archive the file $ tar -cf archive.tar file1 file2 Extract the files $ tar -xf archive.tar
cal Show the calendar for the specified month or year $ cal $ cal -3 $ cal -m 5 $ cal -y 2020
date Show/Set the current date and time $ date Sets the system date and time to given date $ date -s “11/20/2003 12:48:00”
bg Run a program or a process in the background $ bg %[PID]
free Check for the free memory $free
kill Stop a process $ kill <PSID>
nice Run a program with a low priority, niceness values range from -20 to 19, with the former being most favorable, while latter being least $ nice -10 ls -R $ nice –10 ls -R
ps Show current running processes $ps
top Show list of CPU and memory utilization of processes $top
reboot Restart the system $reboot
shutdown Turn off system $shutdown
Exit mobile version