AMP AMP

Useful commands to manage Desktop and Server in Linux - Part 1

Useful commands to manage Desktop and Server in Linux

Some useful commands which is less known to manage Desktop and server more efficiently is described in this article with examples.

sudo command

sudo command helps to give you permission denied error. You need not rewrite the entire command it just grabs the last command.

[user1@linuxhelp~]$ yum install vim
Loaded plugins: fastestmirror, refresh-packagekit, security

You need to be root user to install the vim.

[user1@linuxhelp~]$ sudo yum install vim
Loaded plugins: fastestmirror, refresh-packagekit, security
Settingup installing process
- package vim will be installed
&hellip 
&hellip 

python command

The python command helps to generate simple web page over HTTP and access at port 8000 until the interrupt signal is sent.

[root@linuxhelp~]# python -m SimpleHTTPServer

Go to the browser and give localhost:8000 to list the directory for /

mtr Command

mtr command is the combination of both ping and trace route.

On Debian based Systems

$ sudo apt-get install mtr

On Red Hat based Systems

[root@linuxhelp~]# yum install mtr

Execute the mtr command to start checking the connection between host mtr runs on and google.com

[root@linuxhelp~]# mtr google.com

emacs editor

It is used to automate the task of administrator to open editor.

Press “ Ctrl-x-e” in terminal prompt and work in editor.

nl Command

The nl Command denotes the number of lines in a file. The content of file can be listed using cat command.

[root@linuxhelp~]# cat my.txt 
Hello
Linux
centos

Execute “ nl command” to list them in a numbered order.

[root@linuxhelp~]# nl my.txt 
1 hello
2 linux 
3 centos

shuf Command

It is used to randomly select lines/files/folder from a file/folder.

[root@linuxhelp~]# ls 
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
[root@linuxhelp~]# ls | shuf (shuffle Input)
Music 
Documents 
Templates 
Pictures 
Public 
Desktop 
Downloads 
Videos
[root@linuxhelp~]# ls | shuf -n1 (pick on random selection)
Public
[root@linuxhelp~]# ls | shuf -n1 
Videos
[root@linuxhelp~]# ls | shuf -n1 
Templates
[root@linuxhelp~]# ls | shuf -n1 
Downloads

ss Command

ss means socket statistics. It is used to display more TCP and state information’ s.

[root@linuxhelp~]# ss 
State      Recv-Q Send-Q      Local Address:Port          Peer Address:Port   
ESTAB      0      0           192.168.1.198:41250        *.*.*.*:http    
CLOSE-WAIT 1      0               127.0.0.1:8000             127.0.0.1:41393   
ESTAB      0      0           192.168.1.198:36239        *.*.*.*:http    
ESTAB      310    0               127.0.0.1:8000             127.0.0.1:41384   
ESTAB      0      0           192.168.1.198:41002       *.*.*.*:http    
ESTAB      0      0               127.0.0.1:41384            127.0.0.1:8000

last Command

It displays the history of last logged in users.

[root@linuxhelp~]# last 
server   pts/0        :0               Tue Oct 22 12:03   still logged in   
server   tty8         :0               Tue Oct 22 12:02   still logged in   
&hellip 
...
(unknown tty8         :0               Tue Oct 22 12:02 - 12:02  (00:00)    
server   pts/0        :0               Tue Oct 22 10:33 - 12:02  (01:29)    
server   tty7         :0               Tue Oct 22 10:05 - 12:02  (01:56)    
(unknown tty7         :0               Tue Oct 22 10:04 - 10:05  (00:00)    
reboot   system boot  3.2.0-4-686-pae  Tue Oct 22 10:04 - 12:44  (02:39)    

wtmp begins Fri Oct  4 14:43:17 2007

curl command

The below command is used to obtain your external IP address into your terminal.

[root@linuxhelp~]# curl ifconfig.me
xx.xx.xx.xx

The above command displays external ip address of my machine, now follow the same step to get your external ip address of your system.
If curl package is not installed, apt/yum command to install package.

tree command

To display current directory in tree format, execute the below command.

[root@linuxhelp~]# tree
. 
|-- Desktop 
|-- Documents 
|   `-- 37.odt 
|-- Downloads 
|   |-- attachments.zip 

|   |-- ttf-indic-fonts_0.5.11_all.deb 
|   |-- ttf-indic-fonts_1.1_all.deb 
|   `-- wheezy-nv-install.sh 
|-- Music 
|-- Pictures 
|   |-- Screenshot from 2013-10-22 12:03:49.png 
|   `-- Screenshot from 2013-10-22 12:12:38.png 
|-- Public 
|-- Templates 
`-- Videos 

10 directories, 23 files

pstree

It is used to display all the processes running currently along with associated child process.

[root@linuxhelp~]# pstree 
init---NetworkManager---{NetworkManager} 
     +-accounts-daemon---{accounts-daemon} 
     +-acpi_fakekeyd 
     +-acpid 
     +-apache2---10*[apache2] 
     +-at-spi-bus-laun---2*[{at-spi-bus-laun}] 
     +-atd 
     +-avahi-daemon---avahi-daemon 
     +-bluetoothd 
     +-colord---{colord} 
     +-colord-sane---2*[{colord-sane}] 
     +-console-kit-dae---64*[{console-kit-dae}] 
     +-cron 
     +-cupsd 
     +-2*[dbus-daemon] 
     +-dbus-launch 
     +-dconf-service---2*[{dconf-service}] 
     +-dovecot---anvil 
     ¦          +-config 
     ¦          +-log 
     +-exim4 
     +-gconfd-2 
     +-gdm3---gdm-simple-slav---Xorg 
     ¦       ¦                  +-gdm-session-wor---x-session-manag---evolution-a+ 
     ¦       ¦                  ¦                  ¦                  +-gdu-notific+ 
     ¦       ¦                  ¦                  ¦                  +-gnome-scree+ 
     ¦       ¦                  ¦                  ¦                  +-gnome-setti+ 
     ¦       ¦                  ¦                  ¦                  +-gnome-shell+++ 
     ¦       ¦                  ¦                  ¦                  +-nm-applet--+++ 
     ¦       ¦                  ¦                  ¦                  +-ssh-agent 
     ¦       ¦                  ¦                  ¦                  +-tracker-min+ 
     ¦       ¦                  ¦                  ¦                  +-tracker-sto+ 
     ¦       ¦                  ¦                  ¦                  +-3*[{x-sessi+ 
     ¦       ¦                  ¦                  +-2*[{gdm-session-wor}] 
     ¦       ¦                  +-{gdm-simple-slav} 
     ¦       +-{gdm3} 
     +-6*[getty] 
     +-gnome-keyring-d---9*[{gnome-keyring-d}] 
     +-gnome-shell-cal---2*[{gnome-shell-cal}] 
     +-goa-daemon---{goa-daemon} 
     +-gsd-printer---{gsd-printer} 
     +-gvfs-afc-volume---{gvfs-afc-volume}

< space> Command

< space> Command can be used to avoid recording the history of commands.

[root@linuxhelp~]#  ls
[root@linuxhelp~]#  pwd
[root@linuxhelp~]#  uname
[root@linuxhelp~]#  echo “ hi” 
[root@linuxhelp~]#  who

Execute history command to check if commands or executed or not.

[root@linuxhelp~]# history
   40  cd /dev/ 
   41  ls 
   42  ping www.google.com 
   43  su

stat Command

stat Command displays the status information of a file or filesystem. It shows the status information’ s like file size, block permissions, access permissions, date time modify or changes etc.

[root@linuxhelp~]# stat 34.odt 

  File: `34.odt'  
  Size: 28822         Blocks: 64         IO Block: 4096   regular file 
Device: 801h/2049d    Inode: 5030293     Links: 1 
Access: (0644/-rw-r--r--)  Uid: ( 1000/     avi)   Gid: ( 1000/     avi) 
Access: 2013-10-14 00:17:40.000000000 +0530 
Modify: 2013-10-01 15:20:17.000000000 +0530 
Change: 2013-10-01 15:20:17.000000000 +0530

< alt> . and < esc> .

To put last command argument at prompt, press and hold ‘ Alt‘ or ‘ Esc‘ and continue pressing ‘ .

pv command

pv command is used to echo any kind of text and output in simulating order.

[root@linuxhelp~]# echo " Welcome to linuxhelp.com"  | pv -qL 20
Welcome to linuxhelp.com

mount | column -t

It displays the list of all the mounted filesystem in format with the specifications.

[root@linuxhelp~]# mount | column -t
/dev/sda1    on  /                         type  ext3         (rw,errors=remount-ro) 
tmpfs        on  /lib/init/rw              type  tmpfs        (rw,nosuid,mode=0755) 
proc         on  /proc                     type  proc         (rw,noexec,nosuid,nodev) 
sysfs        on  /sys                      type  sysfs        (rw,noexec,nosuid,nodev) 
udev         on  /dev                      type  tmpfs        (rw,mode=0755) 
tmpfs        on  /dev/shm                  type  tmpfs        (rw,nosuid,nodev) 
devpts       on  /dev/pts                  type  devpts       (rw,noexec,nosuid,gid=5,mode=620) 
fusectl      on  /sys/fs/fuse/connections  type  fusectl      (rw) 
binfmt_misc  on  /proc/sys/fs/binfmt_misc  type  binfmt_misc  (rw,noexec,nosuid,nodev) 
nfsd         on  /proc/fs/nfsd             type  nfsd         (rw)

Clear command

It helps to clean your terminal at once. Option Ctrl+l can also be used to clean.

screen Command

[root@linuxhelp~]# yum install screen

Now press ‘ ?’ help symbol on your keyboard to get help page of screen command and press spacebar on your keyboard to go next page again press space bar to return normal page.
Now press ctrl + A to open another screen.

To list your process running in screen type below command.

[root@linuxhelp~]# screen -ls

file command

It helps to give information about the type of file.

[root@linuxhelp~]# file 34.odt 
34.odt: OpenDocument Text

id command

It helps to print real and effective user and group ids.

[root@linuxhelp~]# id
uid=1000(linux) gid=1000(linux) 
groups=1000(linux),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),109(netdev),111(bluetooth),117(s
FAQ
Q
Why the space command is used?
A
Because the space command is used to avoid the history .
Q
Why the pstree command is using?
A
To list the queries in order to view from the tree shape.
Q
Why the curl command is used?
A
The above command displays external ip address of my machine, now follow the same step to get your external ip address of your system.
If curl package is not installed, apt/yum command to install package.
Q
I need the link for part 2
A
https://www.linuxhelp.com/useful-commands-to-manage-desktopserver-part-2/
Q
good way of exploring commands
A
try to keep in touch with us www.linuxhelp.com