Useful commands to manage Desktop and Server in Linux - Part 2
Useful commands to manage Desktop and Server
Some useful commands which helps you to manage Desktop/Server more efficiently in Linux is illustrated in this article with examples.
> Command
It is used to delete the contents of the file without removing and creating the same file again.
[root@linuxhelp Desktop]# cat my.txt linux windows mac unix android [root@linuxhelp Desktop]# > my.txt [root@linuxhelp Desktop]# cat my.txt
at Command
It is used to schedule a task or command to run at specified time.
[root@linuxhelp Desktop]# at 15:10
at> mkdir dir
at>
job 17 at 2016-03-30 15:10
du Command
It displays the output of the sub folders size within the current directory.
[root@linuxhelp Desktop]# du -h --max-depth=1
4.0K ./mydirc
428K ./mhddfs-0.1.39
500K .
For info about du command: https://www.linuxhelp.com/disk-management-linux-du-command/
expr Command
It helps to do simple mathematical calculation in terminal.
[root@linuxhelp Desktop]# expr 5 + 5 10 [root@linuxhelp Desktop]# expr 5 &ndash 2 3
look Command
It is used to check for words in dictionary.
[root@linuxhelp Desktop]# look ap
A& P
A/P
AP
apa
apabhramsa
apace
Apache
.
.
.
apyrexy
apyrotype
apyrous
yes Command
It is used to display the specified content infinitely.
[root@linuxhelp Desktop]# yes " This is Linuxhelp Tutorial"
This is Linuxhelp Tutorial
This is Linuxhelp Tutorial
This is Linuxhelp Tutorial
This is Linuxhelp Tutorial
This is Linuxhelp Tutorial
. . .
. . . .
. . . . .
This is Linuxhelp Tutorial
This is Linuxhelp Tutorial
factor Command
It displays the factorial of a given number.
[root@linuxhelp Desktop]# factor 25 25: 5 5 [root@linuxhelp Desktop]# factor 27 27: 3 3 3
Using ping with audible output
It is used to check is whether the server is alive or not with audible output.
[root@linuxhelp Desktop]# ping -i 10 -a google.com
PING google.com (216.58.197.78) 56(84) bytes of data.
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=1 ttl=57 time=21.4 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=2 ttl=57 time=6.02 ms
For info about ping command: https://www.linuxhelp.com/ping-command/
tac Command
It prints the content of a text file in reverse order, i.e., from last line to first line.
[root@linuxhelp Desktop]# cat my.txt 1. Linux 2. Windows 3. Mac 4. Android [root@linuxhelp Desktop]# tac my.txt 4. Android 3. Mac 2. Windows 1. Linux
strace Command
strace Command is used display the full details of how the command is executed from the kernel.
[root@linuxhelp Desktop]# strace ls
execve(" /bin/ls" , [" ls" ], [/* 45 vars */]) = 0
brk(0) = 0x16c3000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f79fd614000
access(" /etc/ld.so.preload" , R_OK) = -1 ENOENT (No such file or directory)
open(" /etc/ld.so.cache" , O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=63821, ...}) = 0
mmap(NULL, 63821, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f79fd604000
disown -a & & exit Command
It is used to run the jobs continuously in the background even after you closing the terminal session.
[root@linuxhelp Desktop]# top disown -a & & exit
getconf Command
It displays the machine architecture if it is 32 bit or 64 bit.
[root@linuxhelp Desktop]# getconf LONG_BIT
64
To display Date on the Terminal
Execute this command to see the date and time in the terminal.
[root@linuxhelp Desktop]# while sleep 1 do tput sc tput cup 0 $(($(tput cols)-29)) date tput rc done &
For info about date command: https://www.linuxhelp.com/date-command/
Convert Command
It is used to to produce output in image format.
[root@linuxhelp Desktop]# tree | convert label:@- shot1.png
[root@linuxhelp Desktop]# display shot1.png
watch -t -n1 “ date +%T|figlet”
To display animated digital clock
It shows the animated digital clock in the terminal.
[root@linuxhelp Desktop]# watch -t -n1 " date +%T|figlet"
To check DNS lookup utility by using host and dig Commands
[root@linuxhelp Desktop]# host facebook.com facebook.com has address 173.252.120.68 facebook.com has IPv6 address 2a03:2880:2130:cf24:face:b00c:0:25de facebook.com mail is handled by 10 msgin.vvv.facebook.com. [root@linuxhelp Desktop]# dig facebook.com < < > > DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6 < < > > facebook.com global options: +cmd Got answer: -> > HEADER<
For more info about dig command: https://www.linuxhelp.com/dig-command-query-dns/
To view all of your system resources
[root@linuxhelp Desktop]# dstat
To displays all the shortcuts available for BASH shell using bind
[root@linuxhelp Desktop]# bind -p
" C-g" : abort
" C-xC-g" : abort
" eC-g" : abort
" C-j" : accept-line
" C-m" : accept-line
. . .
. . . .
. . . . .
" C-y" : yank
" e." : yank-last-arg
" e_" : yank-last-arg
" ey" : yank-pop
Alias Command
The command alias is usually a short name that the shell translates into another name or command. Aliases allow you to define new commands by substituting a string for the first token of a simple command. They are located in the ~/.bashrc (bash) or ~/.tcshrc (tcsh) start up files so that they are available to interactive sub shells.
[root@linuxhelp Desktop]#alias c=' clear' [root@linuxhelp Desktop]#c [root@linuxhelp Desktop]#alias 1=' mkdir' [root@linuxhelp Desktop]#1 myfolder [root@linuxhelp Desktop]#ls dir mydir download mydirc download~ myfolder f1.txt my.txt gnome-screenshot.desktop part2.odt [root@linuxhelp Desktop]# unalias c [root@linuxhelp Desktop]#unalias 1
w command
The w command displays the information about the users currently logged into the machine, and their processes.
[root@linuxhelp Desktop]# w
19:05:13 up 1:24, 2 users, load average: 0.04, 0.08, 0.07
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 :0 17:41 1:24m 1:33 1:33 /usr/bin/Xorg :0 -nr -verbose -audit
root pts/0 :0.0 19:04 0.00s 0.03s 0.02s w
ddate command
The ddate command prints the date in Discordant date format. It is used to convert Gregorian date into the Discordian date format and print this on the standard output.
[root@linuxhelp Desktop]# ddate
Today is Boomtime, the 19th day of Discord in the YOLD 3182
To check the information of the operating system
It prints distribution-specific information. If it is not installed apt or yum from package.
[root@linuxhelp Desktop]# lsb_release &ndash a
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 6.4 (Final)
Release: 6.4
Codename: Final
-a displays all the available information like version, id, description, release and codename.
nc command
The nc command stands for Netcat. It is used for debugging and investigating the networking utilities, typically by creating and utilizing raw TCP/IP connections. It is used to check if port 80 is open or not.
[root@linuxhelp Desktop]# nc -zv localhost 22 Connection to localhost 22 port [tcp/ssh] succeeded! [root@linuxhelp Desktop]# nc -zv localhost 80 nc: connect to localhost port 80 (tcp) failed: Connection refused nc: connect to localhost port 80 (tcp) failed: Connection refused
curl command
It displays the the ‘ Geographical Location‘ of the IP address, provided.
[root@linuxhelp Desktop]# curl ipinfo.io
{
" ip" : " xxx.xx.xxx.xx" ,
" hostname" : " linuxhelp.com" ,
" city" : " New Delhi" ,
" region" : " National Capital Territory of Delhi" ,
" country" : " IN" ,
" loc" : " 28.6000,77.2000" ,
" org" : " AS9498 BHARTI Airtel Ltd."
}
find . -user root
It displays the files with respect to the specified user owned files.
[root@linuxhelp Desktop]# find . -user user1
./System Config 03.02.15.docx
./ifconfig command in linux.odt
./Camera
./Camera/V_20150603_090901.mp4
./System Config new.docx
./Ping modified.docx
./dir2
For more info about find command: https://www.linuxhelp.com/find-command/
lsof command
It displays the name of process and service using a specific port.
[root@linuxhelp Desktop]# lsof -iTCP:22 -sTCP:LISTEN
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 1727 root 3u IPv4 10747 0t0 TCP *:ssh (LISTEN)
sshd 1727 root 4u IPv6 10749 0t0 TCP *:ssh (LISTEN)
For more info about lsof command: https://www.linuxhelp.com/find-files-open-process-lsof/
Find the file or directory with specific memory size
The below command used to list the files in the current directory above the specified size recursively.
[root@linuxhelp Desktop]# find -size +50M
./Camera/V_20150603_075317.mp4
./Camera/V_20150603_123558.mp4
./Camera/V_20150603_074918.mp4
./Camera/V_20150603_090901.mp4
./Camera/V_20150603_090703.mp4
./Camera/V_20150603_075447.mp4
./Camera/V_20150603_104407.mp4
pdftk Command
pdftk command is used to merge the multiple PDF file into one PDF file. Before executing this command you should install the pdftk package by using yum for CentOS / RHEL
[root@linuxhelp Downloads]# pdftk file1.pdf file2.pdf cat output merge.pdf
[root@linuxhelp Downloads]# ls
file1.pdf file2.pdf merge.pdf ShellIntro.pdf
After executed the above command now open that merge file and check the status.
To displays the processes and threads of a user
The ps command display the processes and threads of the user. Options L list threads and “ -F” for Full Format Listing.
[root@linuxhelp Desktop]# ps -LF -u root
UID PID PPID LWP C NLWP SZ RSS PSR STIME TTY TIME CMD
root 1 0 1 0 1 4838 1348 0 17:47 ? 00:00:01 /sbin
root 2 0 2 0 1 0 0 0 17:47 ? 00:00:00 [kth]
root 3 2 3 0 1 0 0 0 17:47 ? 00:00:00 [mig]
root 4 2 4 0 1 0 0 0 17:47 ? 00:00:00 [kso]
root 5 2 5 0 1 0 0 0 17:47 ? 00:00:00 [mig]
root 6 2 6 0 1 0 0 0 17:47 ? 00:00:00 [wat]
root 7 2 7 0 1 0 0 0 17:47 ? 00:00:01 [eve]
root 8 2 8 0 1 0 0 0 17:47 ? 00:00:00 [cgr]
root 9 2 9 0 1 0 0 0 17:47 ? 00:00:00 [khe]
For more info about ps command: https://www.linuxhelp.com/ps-command-linux-examples/