Linux Commands
Linux Commands:
- System Basic Commands
- Processes Commands
- File Commands
- Permissions Commands
- Searching Commands
- Link Commands
- Compress Commands
- Job Schedule Commands
- File Transfer Commands
- Root Commands
Root command:
=============
useradd user_name //add new user
passwd user_name //password set and change password
userdel user_name //delete user
cat /etc/passwd //list all users
su - user_name //switch user
su user_name
su //switch root user
logout
exit
# --> root user
$ --> normal user
Manual Command:
man command
example:
man useradd //exit manual pages press 'q'
System basic Commands:
=======================
IP Commands:
============
hostname
hostname -i //Display the IP address(es) of the host
ifconfig
hostname -a //Display the alias name of the host
hostname -d //Display the name of the DNS domain
OS Commands:
============
uname
uname -a
arch
cat /etc/redhat-release
Date Commands:
==============
date
date +%a //locale’s abbreviated weekday name (e.g., Sun)
date +%A //ocale’s full weekday name (e.g., Sunday)
date +%b //locale’s abbreviated month name (e.g., Jan)
date +%B //locale’s full month name (e.g., January)
date +%d //day of month (e.g, 01)
date +%D //date; same as %m/%d/%y
F //full date; same as %Y-%m-%d
u //day of week(1 is monday)
U //week number of year
H //hours(00..23)k(0..23)
I //hours(01..12)l(1..12)
M //minute
S //seconds
m //month
Y //year(2020)y(last 2 digit(20))
Calendar Commands:
==================
cal //current month calender
cal 2010 //2010 calender
cal 5 2010 //2010 may month calender
cal -3 //Display prev/current/next month output.
Disk Commands:
==============
du dir_name or file_name //bytes in file space usage
du -h //human readable
df
df -h
free //free and used memory in the system
free -b //bytes
free -k //KB
free -m //MB
free -g //GB
User Commands:
==============
logname //name of the current user
whoami //name of the current user
who am i //current user name and login time
who //show who is logged on
who -u //show who is logged on with ip address
id //user and group information
users //user names of users currently logged in to the current host
groups //group memberships for each username
groups group_name
uptime //Tell how long the system has been running
w //Displays information about the users currently on the machine and their processes
========================================================
wall //Send a message to everybody's terminal
============
uname
uname -a
arch
cat /etc/redhat-release
Date Commands:
==============
date
date +%a //locale’s abbreviated weekday name (e.g., Sun)
date +%A //ocale’s full weekday name (e.g., Sunday)
date +%b //locale’s abbreviated month name (e.g., Jan)
date +%B //locale’s full month name (e.g., January)
date +%d //day of month (e.g, 01)
date +%D //date; same as %m/%d/%y
F //full date; same as %Y-%m-%d
u //day of week(1 is monday)
U //week number of year
H //hours(00..23)k(0..23)
I //hours(01..12)l(1..12)
M //minute
S //seconds
m //month
Y //year(2020)y(last 2 digit(20))
Calendar Commands:
==================
cal //current month calender
cal 2010 //2010 calender
cal 5 2010 //2010 may month calender
cal -3 //Display prev/current/next month output.
Disk Commands:
==============
du dir_name or file_name //bytes in file space usage
du -h //human readable
df
df -h
free //free and used memory in the system
free -b //bytes
free -k //KB
free -m //MB
free -g //GB
User Commands:
==============
logname //name of the current user
whoami //name of the current user
who am i //current user name and login time
who //show who is logged on
who -u //show who is logged on with ip address
id //user and group information
users //user names of users currently logged in to the current host
groups //group memberships for each username
groups group_name
uptime //Tell how long the system has been running
w //Displays information about the users currently on the machine and their processes
========================================================
wall //Send a message to everybody's terminal
history //System Basic CommandhistoryDisplay the command history list
history -c //clear the history
clear //Clear the terminal screen
history -c //clear the history
clear //Clear the terminal screen
alias clr=clear //create alias string for command with option
alias //list of all alias
unalias clr //remove alias
alias //list of all alias
unalias clr //remove alias
expr 10 + 20 //addition,sub,mul,devision,models
seq 10 //Display a sequence of numbers
seq 1 10
seq 2 2 10
seq 1 10
seq 2 2 10
vmstat
iostat
netstat
sleep 10 //Pause for a specified amount of time(seconds)
ping
echo 'welcome'
iostat
netstat
sleep 10 //Pause for a specified amount of time(seconds)
ping
echo 'welcome'
Process Commands:
=================
ps //current session processes
ps -ef //list of all processes
ps -ef|grep postgres
ps -ef|grep pmon
pstree //Display a tree of running processes.
kill -9 2342 //Terminate a process(2342 is pid)
top //Display a dynamic real-time view of a running linux kernel.
cat /proc/cpuinfo //display the cpu information
cat /proc/meminfo //display the memory information
File Commands:
==============
ls //listout directory and file name only
ls -l or ll //long listing
ls -lrt or ll -rt //reverse order use time
ls -lS or ll -S //sort by file size
ls -la or ll -a //listout hidden files and directory
==================================================
pwd //current/working directory
cd //default home directory
cd directory_name //open directory
cd .. //change back to one step
cd - //change previous path
cd /dir_1/dir_2/dir_3/dir_4
vdir -l /sample/ //list the directory
================================================
mkdir dir_name //create a directory
makdie dir_1 dir_2 dir_3 //create a multiple directory
mkdir -p /dir_1/dir_2/dir_3/ //create a Parental with Subdirectory
===============================================
cat //concatenate
touch
vi editor
nano
===============================================
cat:(only file create,add text and extra add text)
====
cat > file_name //create a new file
cat file_name
cat >> file_name //add text
cat file_1 > file_2 //copy file
cat -n file_name //number all output lines
tac file_name //reverse
============================================================
touch:(create single,multiple empty file and change file timestamps)
======
touch file_empty
touch f1 f2 f3
touch -t 2001011230 file_name //use YYMMDDhhmm instead of current time
================
vi editor:
===========
command mode
insert mode
escape mode
vi filename
command mode:(press esc)
=============
gg //cursor goes to first lines
shfit + g //cursor goes to last line
10gg //cursor goes to 10th line
yy //current line copy
3yy //3 line copy
pp //paste
dd //delete the line
5dd //delete five lines
dw //delete single word
d5w //delete 5 words
x //delete single letter
10x //delete 10 letters
=============
gg //cursor goes to first lines
shfit + g //cursor goes to last line
10gg //cursor goes to 10th line
yy //current line copy
3yy //3 line copy
pp //paste
dd //delete the line
5dd //delete five lines
dw //delete single word
d5w //delete 5 words
x //delete single letter
10x //delete 10 letters
Insert Mode:
============
(press any one a,s,i,o letter to insert)
============
(press any one a,s,i,o letter to insert)
Escape Mode:(press Esc + :)
============
w //only save file
q //unsave and quit(exit file)
! //force
wq //save and quit
wq! //force save and quit
============
w //only save file
q //unsave and quit(exit file)
! //force
wq //save and quit
wq! //force save and quit
find and replace:
=================
%s/source_text/target_text/g
=========================================================
copy command:
=============
cp f1 f2 //copy file f1 to file f2
cp oldfile /home/siva/newfile
cp -rf f1 f2
cp -R /home/siva/d1 /home/muthu/d2
nohup cp -rf /zzz/ /xxx
cp -rf /zzz/ /xxx & //background copy
jobs //list background process
Move Commands:
==============
mv old_file new_file
mv old_file /home/siva/newfile
mv /home/muthu/d1 /home/siva/d2
=================
%s/source_text/target_text/g
=========================================================
copy command:
=============
cp f1 f2 //copy file f1 to file f2
cp oldfile /home/siva/newfile
cp -rf f1 f2
cp -R /home/siva/d1 /home/muthu/d2
nohup cp -rf /zzz/ /xxx
cp -rf /zzz/ /xxx & //background copy
jobs //list background process
Move Commands:
==============
mv old_file new_file
mv old_file /home/siva/newfile
mv /home/muthu/d1 /home/siva/d2
Remove Commands:
================
rm filename
rm -rf filename
rmdir dir_name //remove empty directory
rm -rf dir_name //directory which have contents
================
rm filename
rm -rf filename
rmdir dir_name //remove empty directory
rm -rf dir_name //directory which have contents
head and tail commands:
======================
head file_name //display first 10 lines
head -5 file_name //display first 5 lines
tail file_name //display last 10 lines
tail -5 file_name //display lst 5 lines
head -6 file_name|tail -2 //display 5th and 6th line only
cat file_name|head -6|tail-2
word commands:
==============
wc file_name //list of lines,words,letters
wc -c filename //show letters only
wc -l file_name //show lines only
wc -w file_name //show words only
==============
wc file_name //list of lines,words,letters
wc -c filename //show letters only
wc -l file_name //show lines only
wc -w file_name //show words only
less filename
more file_name
nl file_name //number lines of file
sort file_name //sort lines of text files
sort file_name|uniq //remove duplicate text
more file_name
nl file_name //number lines of file
sort file_name //sort lines of text files
sort file_name|uniq //remove duplicate text
comm file_1 file_2
diff file1 file2
diff3 f1 f2 f3
cmp f1 f2 //compare two files byte by byte
dd if=f1 of=f2 conv=ucase //Data duplicator and used for copying and converting data.
diff file1 file2
diff3 f1 f2 f3
cmp f1 f2 //compare two files byte by byte
dd if=f1 of=f2 conv=ucase //Data duplicator and used for copying and converting data.
==============================================================
Searching Commands:
===================
locate
find
awk
grep
find
awk
grep
locate:
=======
locate file_name //find files by name
=======
locate file_name //find files by name
find:
=====
find -name file_name //find file_name
find . -name file_name
find -iname file_Name //find file ignoring case
find -size 10M
find -empty
find -size 0c
find -amin -5 //last accessed 5 min
find -atime -1 //last accessed 1 day
find -cmin -5 //File’s status was last changed 5 minutes ago.
find -ctime -1 //File’s status was last changed 1 day ago.
find -mmin -3 //last modified 3min
find -mtime -1 //last modified 1day
=====
find -name file_name //find file_name
find . -name file_name
find -iname file_Name //find file ignoring case
find -size 10M
find -empty
find -size 0c
find -amin -5 //last accessed 5 min
find -atime -1 //last accessed 1 day
find -cmin -5 //File’s status was last changed 5 minutes ago.
find -ctime -1 //File’s status was last changed 1 day ago.
find -mmin -3 //last modified 3min
find -mtime -1 //last modified 1day
grep:(print lines marching a pattern)
=====
grep muthu file_name //select matching lines
grep -v 'muthu' file_name //select non-matching lines
grep -i 'muthu' file_name //ignore-case
grep -c 'muthu' file_name //count lines
grep --color 'muthu' file_name
cat file_name|grep -c muthu
=====
grep muthu file_name //select matching lines
grep -v 'muthu' file_name //select non-matching lines
grep -i 'muthu' file_name //ignore-case
grep -c 'muthu' file_name //count lines
grep --color 'muthu' file_name
cat file_name|grep -c muthu
awk:
====
awk {'print $1'} file_name
ls -l|awk {'print $9'} file_name
====
awk {'print $1'} file_name
ls -l|awk {'print $9'} file_name
===============
sed 's/muthu/pearl/' file
sed 's/muthu/pearl/' file > file2
cat file|tr 's' '$'
ls -lrt|cut -d ':' -f2
which file_name
whereis file_name
sed 's/muthu/pearl/' file
sed 's/muthu/pearl/' file > file2
cat file|tr 's' '$'
ls -lrt|cut -d ':' -f2
which file_name
whereis file_name
Permission Commands:
====================
groupadd group_name
groupdel group_name
cat /etc/group
chgrp group_name file_name
usermod -g group_name user_name
chmod u+x file_name
chmod g-r file_name
chmod o+w file_name
umask
chmod 755 file_name
chmod -R 755 file_name
chown user_name file_name
chown -R user_name file_name
chown -R user_name:group_name file_name
chown -R user_name. file_name
=============================================
chmod g-r file_name
chmod o+w file_name
umask
chmod 755 file_name
chmod -R 755 file_name
chown user_name file_name
chown -R user_name file_name
chown -R user_name:group_name file_name
chown -R user_name. file_name
=============================================
Link Commands:
=============
symbolic links or soft link //file and directory f1 f2 f3 f4 remove f3 not working f4
hard link //file only f1 f2 f3 f4 remove f3 working f4
===
soft:
======
ln -s file_1 file_2
ln -s dir1 dir2
hard link //file only f1 f2 f3 f4 remove f3 working f4
===
soft:
======
ln -s file_1 file_2
ln -s dir1 dir2
hard:
=====
ln file_1 file_2
ls -li
================================================
=====
ln file_1 file_2
ls -li
================================================
Compress Commands:
==================
zip //files & dir //65% compress
gzip //only file to move //65% compress
tar //file or folders to file //no compress
gzip //only file to move //65% compress
tar //file or folders to file //no compress
zip file_name.zip file_name
zip -r dir.zip dir_name
zip -e dir.zip dir_name // Password Protected ZIP file
zip -s 1g -r archivename.zip directory_name //splite file 1gb
unzip file_name.zip
unzip dir.zip
gzip file_name
gunzip file_name.gz
gunzip file_name.gz
tar -cvf file_name.tar file_name
tar -cvf dir_name.tar dir_name
tar -xvf file_name.tar
===================================================
tar -cvf dir_name.tar dir_name
tar -xvf file_name.tar
===================================================
Job scheduling commands:
=======================
minute 0-59
hour 0-23
day of month 1-31
month 1-12
day of week 0-6
crontab -e //edit crontab job
30 * * * * /root/backup.sh //Run Cron Job Every 30 Minutes
0 4 * * 1-5 /root/backup.sh //run cron job monday to friday
0 4 * * 1,5 /root/backup.sh //run cron job monday and friday only
crontab -l //list all crontab jobs
crontab -r //remove all jobs
====================================================
30 * * * * /root/backup.sh //Run Cron Job Every 30 Minutes
0 4 * * 1-5 /root/backup.sh //run cron job monday to friday
0 4 * * 1,5 /root/backup.sh //run cron job monday and friday only
crontab -l //list all crontab jobs
crontab -r //remove all jobs
====================================================
Comments
Post a Comment