0% found this document useful (0 votes)
6 views

Linux Commands (st2)

The document describes various date, uptime, hostname, uname, which, cal, bc, ps, bg, fg, nice, ifconfig, ping and traceroute commands in Linux/Unix operating systems. It provides examples of how to use each command and the various options available.

Uploaded by

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

Linux Commands (st2)

The document describes various date, uptime, hostname, uname, which, cal, bc, ps, bg, fg, nice, ifconfig, ping and traceroute commands in Linux/Unix operating systems. It provides examples of how to use each command and the various options available.

Uploaded by

yashika1587.be21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Date commands:

date = display system current time


date -u = display time in UTC(coordinated universal time) time zone
date --date="02/15/2023" = dispalay given string in date format
date --d="15 feb 2023" = dispalay given string in date format
date --d="2 years ago 11:12:13" = dispalay given string in date format
##5 seconds ago, yesterday, 2 month ago, 10 days ago,
date --d="next tue" = date and time for upcoming particular week day
##2 day, tomorrow, 1 year,
date --set="Tue Nov 13 15:34:32 IST 2018" = set date of system
date --file=file.txt = display dates from file in date format
date -r file.txt = display last modified timestamp of file
date "+%D" = display date in ddmmyy
#%D: Display date as mm/dd/yy.
#%d: Display the day of the month (01 to 31).
#%a: Displays the abbreviated name for weekdays (Sun to Sat).
#%A: Displays full weekdays (Sunday to Saturday).
#%h: Displays abbreviated month name (Jan to Dec).
#%b: Displays abbreviated month name (Jan to Dec).
#%B: Displays full month name(January to December).
#%m: Displays the month of year (01 to 12).
#%y: Displays last two digits of the year(00 to 99).
#%Y: Display four-digit year.
#%T: Display the time in 24 hour format as HH:MM:SS.
#%H: Display the hour.
#%M: Display the minute.
#%S: Display the seconds.
# ^ for capital letters.
date "+%D %T" = display date in ddmmyy with time
date "+%Y-%m-%d" = display date with - seperated
date "+%Y/%m/%d" = display date with / seperated
date "+%A %B %d %T %y" = display day, month, date, time, year

Uptime commands:
uptime = display current time, systems uptime and cpu usage of 1,5 & 15 minutes
lscpu = to check cpu detalils
uptime -h = help
uptime -p = display only uptime
uptime -s = display system up since
uptime -V = display uptime version

Hostname commnads:
hostname = display long host name
hostname -a = display alias name of the host system
hostname -A = display all long host name
hostname -b = set deafult hostname if not available
hostname -d = display domain name, empty if not available
hostname -f = display long host name
hostname -i = display ip address of host
hostname -I = display all ip adreesses of host
hostname -s = display short host name
hostname -V = display version of hostname
hostname new_hostname = to set new hostname
hostname -F file.txt = set hostname from file

Uname (unix name) commands:


uname = displays informantion about system
uname -a = Kernel name, network node hostname, kernel release date, kernel version, machine
hardware name, hardware platform, operating system
uname -s = displays kernel name
uname -n = display hostname of network node
uname -r = display kernel release date
uname -v = display current kernel version
uname -m = display machine hardware name
uname -p = display type of processor
uname -i = display platform of hardware
uname -o = display operating system

Which commands:
which cat = display path of cat command
which -a cat = display all matching path of cat command

Cal (calender) commands:


cal = display calender of current month
cal -3 = display calender of previous, current and next month
cal -y = display calender of current year
cal 08 2002 = display calender of august 2002
cal 2013 = display calender of mentioned year
cal 2018 | more/less = display calender with navigation
cal -j = display calender of current month in julian calender
cal -s = display sunday as first day of month
cal -m = display monday as first day of month
cal -V = display version of cal command

Bc (basic calculator) commands:


#1.Arithmetic operators (+,-,*,/,%,^):
echo "30+5" | bc = performs addition
echo "5^5" | bc = performs power
x = `echo "5*5" | bc` \n echo $x = to store value in variable and print it
#2.Assignment operators (+,-,*,/,%,^):
echo "var=50;var" | bc = store value in variable & print
echo "var=50;var^2" | bc = store, calculate & print
x = `echo "var=5;var^2" | bc` \n echo $x = store in another variable, calculate & print
#3.Increment or Decrement operators (++,--):
echo "var=10;var++" | bc = post increment & print
echo "var=10;++var" | bc = pre increment & print
echo "var=10;var--" | bc = post decrement & print
echo "var=10;--var" | bc = pre decrement & print
#4.Comparison or Relational operators (<,<=,>,>=,==,!=),(1 true, 0 false):
echo "25>39" | bc = compare & results
echo "25==39" | bc = compare & results
#5.Logical or Boolean operators (&&, ||, !),(1 true, 0 false):
echo "25 && 22" | bc = Results 1 if both expressions are non-zero
echo "0 && 5" | bc = Results 1 if either expression is non-zero
#6.Math functions: we'll se in shell scripting
#7.Conditional statements (): we'll se in shell scripting
#8.Iterative statements (): we'll se in shell scripting
#write arithmetic expressions in a file and then execute
cat > file.txt
50+55;
10/2;
var = 10*20
var
print var
quit
ctrl+d, to save file
#execute file
bc file.txt
bc -q file.txt
Ps (process status) commands: used to list
the currently running processes
ps = Result contains four columns of information.
PID - the unique process ID
TTY - terminal type that the user is logged into
TIME - amount of CPU in minutes and seconds that the process has been running
CMD - name of the command that launched the process.
ps -ef / -aux = List currently running process in full format
ps -ax = List currently running process
ps -u <username> = List process for specific user
ps -C <command> = List process for given command
ps -p <PID> = List process with given PID
ps -ppid <PPID> = List process with given ppid (parent process ID)
pstree = Show process in hierarchy
ps -U root -u root u = Show process running by root

Bg commands: place the suspended job in


the background / place foreground jobs in
background.
jobs = display stopped commands with id
cat > abc.txt & ctrl+z = to execute and stop command
bg %ID = place job in background in running state

Fg commands: restarts a suspended job in


the foreground / place background job in
foreground.
jobs = display stopped commands with id
fg %ID = brings job to foreground
#options of bg & fg,
#%n : Refer to job number n.
#%str : Refer to a job which was started by a command beginning with str.
fg %c = it will command starting with c to foreground (if there are multiple commands starting with c
it will show error)
#%?str : Refer to a job which was started by a command containing str.
#%% or %+ : Refer to the current job. fg and bg will operate on this job if no job_spec is given.
#%- : Refer to the previous job.

Nice commands: helps in execution of a


program/process with modified scheduling
priority
#priority refers from -20 to +19, wherer +19 reprsent lowest & -20 highest priority.
ps -l = to check nice value of running process
top = to check nice value of running process
nice = display nice value of terminal
nice -20 ping www.google.com = to set highest priority to ping command
nice --20 ping www.google.com = to set lowest priority to ping command
#renice: change priority of running process
ps -el | grep gnome-terminal = to check priority of temrinal
renice -n 5 -p 5529 = -n 5 to set priority, -p specify process id of terminal

Ifconfig (interface congifuration)


commands: configure and view the status of
the network interfaces in Linux o s
ifconfig = to check number of active network available on system
ifconfig network_interface_name = to chek specific network information
ifconfig network_interface_name mtu 2000 = to change maximum transmission unit
ifconfig network_interface_name down = to stop specific network service
ifconfig network_interface_name up = to start specific network service
ifconfig network_interface_name inet new_ip = to set new ip address to system
ifconfig network_interface_name netmask new_ip = to set new ip address of netmask to system
(255.255.255.0 to 255) to connect number of system to network
ifconfig network_interface_name broadcast new_ip = to set new ip address of broadcast to system
ifconfig -a = to check all active & inactive network interface
ifconfig network_interface_name promisc = to enable Promiscuous Mode for specific interface
ifconfig network_interface_name -promisc = to enable Promiscuous Mode for specific interface

Ping (packet internet groper) commands:


ping www.google.com = check network connectivity between host & server
ping -c 5 www.google.com = it will send 5 packets to server (5 pings)
ping -s 40 -c 5 www.google.com = to control size of packet
ping -i 2 www.google.com = it will wait for 2sec for sending next packet
ping -f www.google.com = to test network performance (flooding with ping)
ping -p ff www.google.com = to fill packet with data
ping -c 5 -M want www.google.com = to find out maximum MTU a TCP pth can take

Traceroute commands:
treaceroute www.chitkara.edu.in = display the routes while connecting to server
traceroute -In www.chitkara.edu.in = display the routes details while connecting to server
traceroute -w15 www.chitkara.edu.in = wait time
traceroute www.chitkara.edu.in -n = to disable hostname
traceroute www.chitkara.edu.in -w 5 = wait time
traceroute -n www.chitkara.edu.in -q 3 = configure number of queries per hope
traceroute -n www.chitkara.edu.in -f 8 = configure TTL value to start with

You might also like