0% found this document useful (0 votes)
457 views9 pages

Essential Linux Command Overview

This document provides an overview of essential Linux commands and what they are used for. It lists commands such as ls, cd, mkdir, pwd, cat, cp, mv, rm, find, uname, lscpu, df, du, info, man, whatis, type, alias, unalias, touch, more, less, wc, cut, grep, sed, split, sort, uniq, compress, uncompress, gzip, tar, cal, date and describes what each command is used for in 3 sentences or less. The document serves as a quick reference guide for common Linux commands and their purposes.

Uploaded by

Naeem Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
457 views9 pages

Essential Linux Command Overview

This document provides an overview of essential Linux commands and what they are used for. It lists commands such as ls, cd, mkdir, pwd, cat, cp, mv, rm, find, uname, lscpu, df, du, info, man, whatis, type, alias, unalias, touch, more, less, wc, cut, grep, sed, split, sort, uniq, compress, uncompress, gzip, tar, cal, date and describes what each command is used for in 3 sentences or less. The document serves as a quick reference guide for common Linux commands and their purposes.

Uploaded by

Naeem Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
  • Introduction to Linux Commands
  • Basic Commands
  • System Information and Search
  • Text Processing and Filters
  • Compression and Archiving
  • Process Management and User Commands
  • Filesystem Permissions

Essential Linux Commands

Prepared By: Aamir Pinger

[Link]/AamirPingerOfficial [Link]/AamirPinger

[Link]/in/AamirPinger
LINUX ESSENTIAL COMMANDS

Commands What it does

ls List down all the contents of a director

cd /bin/ Changes directory and goes to bin dir

the tilde (~) sign signifies the user’s home dir – change dir
cd ~
to home director

cd .. Means to change directory one level up

mkdir A command used to create directories

Short for present working directory. This command will


pwd
display the directory where you are currently in

Command to print all the contents of provided filename on


cat <filename>
the screen

cp /home/ /tmp/ Copy contents of /home/ to /tmp

mv Move the file [Link] to the /newDirectoryName/ directory.


/directoryName/[Link] You can also use this command to move the entire directory
t to another
/newDirectoryName/ Directory

Delete the file [Link]. Take extra precaution in using the rm


rm [Link]
command, especially when you are logged in as root

The find command is a powerful tool that you can use when
searching using the command line. The command here will
find / -name “linux*”
search for any file or directory with a name that starts with
linux

This command displays information about the machine, the


uname -a
processor architecture, and the operating system details.

lscpu This command returns more information about the system

2
LINUX ESSENTIAL COMMANDS

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

This command displays the disk space usage in all of the


mounted devices. The -h option presents the results in a
df -h
human readable output, using G for gigabytes or M for
megabytes sizes

This command displays all the files inside the specified


du ~/Downloads directory and their corresponding file sizes. You can also
specify a filename

The –s option provides the total file size of the specified


du ~/Downloads -sh
directory and -h makes it human readable form

Keys to
Purpose Example
Use

Shows online information about


info $ info uname
a command

Shows details (manual) of a


man $ man uname
command

Shows a short description of a


whatis $ whatis uname
specific keyword

Shows the location of a


type $ type uname
command file

Assign a command alias – $ alias t=type


alias
especially useful for long $ t uname

3
LINUX ESSENTIAL COMMANDS

commands $ alias

unalias Remove command alias $ unalias t

cd Change directory $ cd Desktop/

pwd Displays the current directory $ pwd

$ ln -s [file] [soft-link-to-
Create links to files and
ln file]
directories
$ ln -s [Link] [Link]

To trigger a file stamp update


touch $ touch [Link]
for a file

$ find [dir-path] -name


Search for a file based on the
find [filename]
name
$ find . -name [Link]

whereis Search for executable files $ whereis uname

Search for files in the


which directories part of the PATH $ which uname
variable

$ dd conv=ucase
Type Hello world ctrl+d
$ echo “hello world > [Link]
dd Copy lines of data
$ dd if=[Link] of=[Link]
conv=ucase
$ cat [Link]

$ echo “hello world > [Link]


$ echo “hello world > [Link]
Display the results of
diff $ diff [Link] [Link] -s
comparing two files
$ echo “hello world123 > [Link]
$ diff [Link] [Link] -s

4
LINUX ESSENTIAL COMMANDS

Show a text file one page at a $ ls -R > [Link]


more time – display can only go $ more [Link]
forward $ ls -R | more

Show a text file one page at a


$ less [Link]
less time – display can only go
$ ls -R | less
forward and backwards

Display the count of the number


wc of characters, words, and $ wc [Link]
lines in a file

cat Show a text file in one output $ cat [Link]

$ cut -b 1 [Link]
cut Get sections of text in a file $ cut -b 1-3 [Link]
$ cut -b 1,3 [Link]

$ cat [Link] | grep Desktop


Display results of finding
grep $ cat [Link] | grep -i desktop
expressions in a file
$ grep -i "desktop" [Link]

First occurance in every line will be


changed
$ sed 's/Desktop/Dashboard/' [Link]
Perform editing commands, 2nd occurance in every line will be
sed
then copy to a standard output changed
$ sed 's/Desktop/Dashboard/2' [Link]
All occurances will be changed
$ sed 's/Desktop/Dashboard/g' [Link]

$ split [Link]
$ ls
Specify a size to break a file $ rm x*
split
into -l100 is 100 lines per file
$ split -l100 [Link]
$ ls

5
LINUX ESSENTIAL COMMANDS

sort Arrange the lines in a file $ sort [Link]

$ echo “Karachi
Karachi
Lahore
Islamabad
Keep unique lines in a file and Islamabad
uniq
delete duplicates Lahore” > [Link]
$ cat [Link]
$ uniq [Link]
$ uniq [Link] -c
$ uniq [Link] -d

compre
Use to compress a file $ compress -v [Link]
ss

If a file was compressed with a


uncomp
compress command, use this to $ uncompress [Link].Z
ress
decompress

Use GNU Zip to decompress


gunzip $ gunzip -c [Link] > [Link]
files

gzip Compress files with GNU Zip $ gzip -c [Link] > [Link]

Archive the file


Archive files with one or more $ tar -cf [Link] file1 file2
tar
directories Extract the files
$ tar -xf [Link]

$ cal
Show the calendar for the $ cal -3
cal
specified month or year $ cal -m 5
$ cal -y 2020

$ date
Show/Set the current date and
date Sets the system date and time to given
time
date

6
LINUX ESSENTIAL COMMANDS

$ date -s "11/20/2003 [Link]"

Run a program or a process in


bg the background
$ bg %[PID]

free Check for the free memory $ free

kill Stop a process $ kill <PSID>

Run a program with a low


priority, niceness values range
$ nice -10 ls -R
nice from -20 to 19, with the former
$ nice --10 ls -R
being most favorable, while
latter being least

Show current running


ps processes
$ ps

Show list of CPU and memory


top $ top
utilization of processes

reboot Restart the computer $ reboot

shutdow
Turn off computer $ shutdown
n

Adding user from CLI need few steps/commands at CLI

First, login as root by using the command su

aamir@ap-linux:~$ su
Password:
root@ap-linux:/home/aamir#

7
LINUX ESSENTIAL COMMANDS

● Add user by using following command syntax

root@ap-linux:/home/aamir# /usr/sbin/useradd -c "Test User" test


● Once done with above command type passwd

root@ap-linux:/home/aamir# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@ap-linux:/home/aamir#

8
LINUX ESSENTIAL COMMANDS

● To modify an account, use the usermod command

● To delete the user account, use the /usr/sbin/userdel <username>


command

● To add a user group, you need to use the command groupadd


<groupname>

● For example, let’s create a group named office. To create this group,

root@ap-linux:/home/aamir# groupadd office


● To add test user which we create recently to above created office group

root@ap-linux:/home/aamir# usermod -G office test


● To delete the group, use the command groupdel office

● A user and group account owns a Linux file or directory. To see the owner
of a particular file

aamir@ap-linux:~$ ls -l <filename>
● To change the ownership of any file from one user to another user

aamir@ap-linux:~$ chown <newuser> <filename>


● To change the group owner of the file

aamir@ap-linux:~$ chgrp <newgroup> <filename>

You might also like