Basic Linux Commands
Basic Linux Commands
Then learn Basic linux shell command from below simple tutorials. Which will help you to understand Linux/Unix shell command better.
INDEX
• File Handling • Text Processing • System Administration • Process Management • Archival • Network • File Systems • System Commands • Other Useful command
File Handling commands
mkdir — make directories
Usage: mkdir [OPTION] DIRECTORY…
eg.
#mkdir sudoadmin
ls — list directory contents
Usage: ls [OPTION]… [FILE]…
eg.
#ls sudoadmin
cd — changes directories
Usage: cd [DIRECTORY]
eg.
#cd sudoadmin
pwd — print name of current working directory
Usage: pwd
vim — Vi Improved, a programmers text editor
Usage: vim [OPTION] file]…
eg.
#vim file1.txt
cp — copy files and directories
Usage: cp [OPTION]… SOURCE DEST
eg.
#cp sample.txt sample_copy.txt
cp sample_copy.txt target_dir
mv — move (rename) files
Usage: mv [OPTION]… SOURCE DEST
eg.
#mv source.txt target_dir #mv old.txt new.txt
rm – remove files or directories
Usage: rm [OPTION]… FILE…
eg.
#rm file1.txt #rm rf some_dir
find — search for files in a directory hierarchy
Usage: find [OPTION] [path] [pattern]
eg.
#find file1.txt #find name file1.txt
history — prints recently used commands
Usage: history
Pattern
A Pattern is an expression that describes a set of strings which is used to give a concise description of a set, without having to list all elements.
eg. ab*cd matches anything that starts with ab and ends with cd etc.
eg. prints all text files
#ls *.txt
Text Processing
cat — concatenate files and print on the standard output.
Usage: cat [OPTION] [FILE]…
eg.
#cat file1.txt #cat -n file1.txt
echo — display a line of text Usage: echo [OPTION] [string] … eg.
#echo "I love India" #echo $HOME
grep – print lines matching a pattern
Usage: grep [OPTION] PATTERN [FILE]…
eg.
grep -i "apple" sample.txt
wc – print the number of newlines, words, and bytes in files
Usage: wc [OPTION]… [FILE]…
eg.
wc file1.txt wc -L file1.txt
sort — sort lines of text files
Usage: sort [OPTION]… [FILE]…
eg.
#sort file1.txt #sort -r file1.txt
Linux File Permissions
3 types of file permissions — read, write, execute
10 bit format from ‘ls -l’ command
1 2 3 4 5 6 7 8 9 10
file type owner group others
eg.
drwxrwr — means owner has all three permissions, group has read and write, others have only read permission
eg. read – 4, write – 2, execute 1 rwxrwr = 764 rwrwxwx = 673
System Administration
chmod — change file access permissions Usage: chmod [OPTION] [MODE] [FILE] eg.
#chmod 744 calculate.sh
chown — change file owner and group
Usage: chown [OPTION]… OWNER[:[GROUP]] FILE…
eg.
#chown root:hitesh myfile.txt
su — change user ID or become superuser
Usage: su [OPTION] [LOGIN]
eg.
#su hitesh,
passwd — update a user’s authentication tokens(s)
Usage: passwd [OPTION]
eg.
passwd hitesh
who — show who is logged on
Usage: who [OPTION]
eg.
#who #who -b #who -q
Process Management
ps — report a snapshot of the current processes
Usage: ps [OPTION]
eg.
#ps #ps -el #ps -ef
kill — to kill a process(using signal mechanism)
Usage: kill [OPTION] pid
eg.
#kill -9 2275
bg — make a foreground process to run in background
Usage: type ‘ctrl+z’ and then ‘bg ‘
eg.
#/usr/bin/php /home/hitesh/helloworld.php //type "ctrl+z" and then type "bg"
jobs — displays the names and ids of background jobs
Usage: jobs
eg.
#jobs [1]- Stopped /usr/bin/php /home/hitesh/helloworld.php
fg — to make background process as foreground process
Usage: fg [job id]
eg.
#fg 1
Archival
tar — to archive a file
Usage: tar [OPTION] DEST SOURCE
eg.
#tar -cvf /home/archive.tar /home/original
eg. to extract tar file
#tar -xvf /home/archive.tar
zip — package and compress (archive) files
Usage: zip [OPTION] DEST SOURSE
eg.
#zip original.zip original
unzip — list, test and extract compressed files in a ZIP archive
Usage: unzip filename
eg.
#unzip original.zip
Network
ssh — SSH client (remote login program)
“ssh is a program for logging into a remote machine and for executing commands on a remote machine”
Usage: ssh [options] [user]@hostname
eg.
#ssh X guest@192.168.1.10
scp — secure copy (remote file copy program)
“scp copies files between hosts on a network”
Usage: scp [options] [[user]@host1:file1] [[user]@host2:file2] eg.
#scp file1.txt guest@192.168.1.10:/home/anki/
File Systems
fdisk — partition manipulator
eg.
sudo fdisk -l
mount — mount a file system
Usage: mount t type device dir
eg.
mount /dev/sda5 /media/target
umount — unmount file systems
Usage: umount [OPTIONS] dir | device…
eg.
umount /media/target
du — estimate file space usage
Usage: du [OPTION]… [FILE]…
eg.
#du
df — report filesystem disk space usage
Usage: df [OPTION]… [FILE]…
eg.
#df -hla
quota — display disk usage and limits
Usage: quota [OPTION]
eg.
#quota -v
System Command
reboot — reboot the system
Usage: reboot [OPTION]
eg.
#reboot
poweroff — power off the system
Usage: poweroff [OPTION]
eg.
#poweroff
Editor commands
kate — KDE Advanced Text Editor
Usage: kate [options][file(s)]
eg.
#kate file1.txt
vim — Vi Improved, a programmers text editor
Usage: vim [OPTION] [file]…
eg.
#vi hello.c
gedit – A text Editor. Used to create and edit files.
Usage: gedit [OPTION] [FILE]…
eg.
#gedit
Other Useful command
sed — stream editor for filtering and transforming text
Usage: sed [OPTION] [inputfile]…
eg.
#sed 's/love/hate/g' loveletter.txt
awk – pattern scanning and processing language
eg.
#awk F: '{ print $1 }' sample_awk.txt
find — search for files in a directory hierarchy
Usage: find [OPTION] [path] [pattern]
eg.
#find name file1.txt
locate — find or locate a file
Usage: locate [OPTION]… FILE…
eg.
#locate file1.txt
man <command> — shows all information about the command
eg.
#man ls
<command> –help — shows the available options for that command
eg.
#ls --help
Was this article Helpful? [ratings]
If Have any questions or any suggestion for me,
Please reply in comments.
Cool blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple tweeks would really make my blog jump out. Please let me know where you got your design. Thanks
Custom made