Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
224 views

Linux Essential Commands

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
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
224 views

Linux Essential Commands

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
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Essential Linux Commands

Prepared By: Aamir Pinger

fb.com/AamirPingerOfficial github.com/AamirPinger

linkedin.com/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 file1.txt to the /newDirectoryName/ directory.


/directoryName/file1.tx You can also use this command to move the entire directory
t to another
/newDirectoryName/ Directory

Delete the file file1.txt. Take extra precaution in using the rm


rm file1.txt
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 abc.txt newAbc.txt

To trigger a file stamp update


touch $ touch abc.txt
for a file

$ find [dir-path] -name


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

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 > abc.txt
dd Copy lines of data
$ dd if=abc.txt of=newabc.txt
conv=ucase
$ cat newabc.txt

$ echo “hello world > abc.txt


$ echo “hello world > abc1.txt
Display the results of
diff $ diff abc.txt abc1.txt -s
comparing two files
$ echo “hello world123 > newabc.txt
$ diff abc.txt newabc.txt -s

4
LINUX ESSENTIAL COMMANDS

Show a text file one page at a $ ls -R > abc.txt


more time – display can only go $ more abc.txt
forward $ ls -R | more

Show a text file one page at a


$ less abc.txt
less time – display can only go
$ ls -R | less
forward and backwards

Display the count of the number


wc of characters, words, and $ wc abc.txt
lines in a file

cat Show a text file in one output $ cat abc.txt

$ cut -b 1 abc.txt
cut Get sections of text in a file $ cut -b 1-3 abc.txt
$ cut -b 1,3 abc.txt

$ cat abc.txt | grep Desktop


Display results of finding
grep $ cat abc.txt | grep -i desktop
expressions in a file
$ grep -i "desktop" abc.txt

First occurance in every line will be


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

$ split abc.txt
$ ls
Specify a size to break a file $ rm x*
split
into -l100 is 100 lines per file
$ split -l100 abc.txt
$ ls

5
LINUX ESSENTIAL COMMANDS

sort Arrange the lines in a file $ sort abc.txt

$ echo “Karachi
Karachi
Lahore
Islamabad
Keep unique lines in a file and Islamabad
uniq
delete duplicates Lahore” > abc.txt
$ cat abc.txt
$ uniq abc.txt
$ uniq abc.txt -c
$ uniq abc.txt -d

compre
Use to compress a file $ compress -v abc.txt
ss

If a file was compressed with a


uncomp
compress command, use this to $ uncompress abc.txt.Z
ress
decompress

Use GNU Zip to decompress


gunzip $ gunzip -c abc.zip > newabc.txt
files

gzip Compress files with GNU Zip $ gzip -c abc.txt > abc.zip

Archive the file


Archive files with one or more $ tar -cf archive.tar file1 file2
tar
directories Extract the files
$ tar -xf archive.tar

$ 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 12:48:00"

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