LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Blogs > Nbiser
User Name
Password

Notices

Rate this Entry

Basic CLI (Command Line Interface) Tools Pt. 2

Posted 06-19-2013 at 07:35 PM by Nbiser

In Pt. 1, I covered basic command line tools and commands. I will continue that theme here, in Pt. 2.

First I would like to cover the command ps. This command is used to view processes. In its basic form without any options its output looks like this:
Code:
nbiser@linux-vqbm:~> ps
  PID TTY          TIME CMD
14933 pts/1    00:00:00 ps
17047 pts/1    00:00:00 bash
Here it only shows the most basic processes that are running on the system. PID stands for the process ID, time shows how long the process has been running, CMD shows the command used to launch the process while TTY is the code used to identify the terminal.

I will now show you a more advanced (and more useful) form of ps. The ps -u user command.
Code:
nbiser@linux-vqbm:~> ps -u nbiser
  PID TTY          TIME CMD
 1543 ?        00:00:00 startkde
 2703 ?        00:00:00 dbus-launch
 2730 ?        00:00:00 dbus-daemon
 2906 ?        00:00:00 kdeinit4
 3431 ?        00:00:00 klauncher
 3463 ?        00:00:02 kded4
 3710 ?        00:00:00 kglobalaccel
 3817 ?        00:00:00 kwalletd
 3835 ?        00:00:00 kactivitymanage
 3865 ?        00:00:00 kwrapper4
 3879 ?        00:00:00 ksmserver
 3954 ?        00:00:40 kwin
 4601 ?        00:00:13 plasma-desktop
 4621 ?        00:00:01 knotify4
 5194 ?        00:00:00 kuiserver
 5473 ?        00:00:00 kaccess
 5480 ?        00:00:00 nepomukserver
 5483 ?        00:00:32 vmtoolsd
 5486 ?        00:00:00 nepomukservices
 5488 ?        00:00:02 krunner
 5496 ?        00:00:00 polkit-kde-auth
 5497 ?        00:00:00 nepomukcontroll
 5500 ?        00:00:00 klipper
 5502 ?        00:00:00 kmix
 5508 ?        00:00:01 pulseaudio
 5545 ?        00:00:00 akonadi_control
 5548 ?        00:00:00 akonadiserver
 5550 ?        00:00:06 mysqld
 5590 ?        00:00:00 akonadi_agent_l
 5591 ?        00:00:00 akonadi_agent_l
 5592 ?        00:00:00 akonadi_agent_l
 5593 ?        00:00:00 akonadi_agent_l
 5594 ?        00:00:00 akonadi_maildis
 5595 ?        00:00:00 akonadi_mailfil
 5596 ?        00:00:00 akonadi_nepomuk
 5598 ?        00:00:07 virtuoso-t
 5658 ?        00:00:00 kio_http_cache_
 5668 ?        00:00:00 nepomukservices
 5669 ?        00:00:00 nepomukservices
 5670 ?        00:00:00 nepomukservices
 6271 ?        00:00:00 apper-sentinel
11415 ?        00:00:00 krandrtray
14090 ?        00:01:01 firefox
14905 ?        00:00:00 kmozillahelper
15237 pts/1    00:00:00 ps
17014 ?        00:00:00 gconfd-2
17045 ?        00:00:03 konsole
17047 pts/1    00:00:00 bash
The option -u makes the terminal show all of the processes that that specified user is running.

Another option that can be used is:
Code:
nbiser@linux-vqbm:~> ps -e
  PID TTY          TIME CMD
    1 ?        00:00:02 systemd
    2 ?        00:00:00 kthreadd
    3 ?        00:00:00 ksoftirqd/0
    6 ?        00:00:00 migration/0
    7 ?        00:00:18 rcuc/0
    8 ?        00:00:00 rcun/0
    9 ?        00:00:00 rcub/0
   10 ?        00:00:00 rcun/1
   11 ?        00:00:00 rcub/1
   12 ?        00:00:02 watchdog/0
   13 ?        00:00:00 cpuset
   14 ?        00:00:00 khelper
This shows all of the options running on the system. (Please note: I shortened the output of ps -e because it is way to long to post.)

And finally, ps -u U user:
Code:
nbiser@linux-vqbm:~> ps u U nbiser
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
nbiser    1543  0.0  0.1  13000  1480 ?        Ss   12:06   0:00 /bin/sh /usr/bin/startkde
nbiser    2703  0.0  0.0  22236   556 ?        S    12:06   0:00 dbus-launch --sh-syntax --exit-with-session
nbiser    2730  0.0  0.1  29592  2036 ?        Ss   12:06   0:00 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
nbiser    2906  0.0  1.8 312604 18784 ?        Ss   12:06   0:00 kdeinit4: kdeinit4 Running...                  
nbiser    3431  0.0  0.6 316288  7008 ?        S    12:06   0:00 kdeinit4: klauncher [kdeinit] --fd=9           
nbiser    3463  0.0  2.3 810504 23788 ?        Sl   12:06   0:02 kdeinit4: kded4 [kdeinit]                      
nbiser    3710  0.0  1.1 392940 11576 ?        S    12:06   0:00 kdeinit4: kglobalaccel [kdeinit]               
nbiser    3817  0.0  1.0 396192 10520 ?        S    12:06   0:00 kdeinit4: kwalletd [kdeinit]                   
nbiser    3835  0.0  1.5 251164 15888 ?        S    12:06   0:00 /usr/bin/kactivitymanagerd
nbiser    3865  0.0  0.0   4184   352 ?        S    12:06   0:00 kwrapper4 ksmserver
nbiser    3879  0.0  1.3 468216 13972 ?        Sl   12:06   0:00 kdeinit4: ksmserver [kdeinit]                  
nbiser    3954  0.2  5.3 615296 54888 ?        Sl   12:06   0:42 kwin
nbiser    4601  0.0  7.9 1190884 81192 ?       Sl   12:06   0:14 kdeinit4: plasma-desktop [kdeinit]             
nbiser    4621  0.0  2.8 1017080 29136 ?       Sl   12:06   0:01 /usr/bin/knotify4
nbiser    5194  0.0  1.6 249576 16480 ?        S    12:06   0:00 /usr/bin/kuiserver
nbiser    5473  0.0  1.2 400692 12940 ?        S    12:06   0:00 kdeinit4: kaccess [kdeinit]                    
nbiser    5480  0.0  0.5 388660  5844 ?        Sl   12:06   0:00 kdeinit4: nepomukserver [kdeinit]              
nbiser    5483  0.1  1.8 224480 18996 ?        S    12:06   0:32 /usr/bin/vmtoolsd -n vmusr --blockFd 3
nbiser    5486  0.0  3.0 868848 31632 ?        SNl  12:06   0:00 /usr/bin/nepomukservicestub nepomukstorage
nbiser    5488  0.0  2.9 761384 29932 ?        Sl   12:06   0:03 kdeinit4: krunner [kdeinit]                    
nbiser    5496  0.0  1.6 344824 16792 ?        Sl   12:06   0:00 /usr/lib64/kde4/libexec/polkit-kde-authentication-agent-1
nbiser    5497  0.0  1.4 252564 15092 ?        S    12:06   0:00 /usr/bin/nepomukcontroller
nbiser    5500  0.0  1.3 407260 13472 ?        S    12:06   0:00 kdeinit4: klipper [kdeinit]                    
nbiser    5502  0.0  1.9 546116 20068 ?        Sl   12:06   0:00 kdeinit4: kmix [kdeinit]                       
nbiser    5508  0.0  0.6 361828  6416 ?        Sl   12:06   0:01 /usr/bin/pulseaudio --start
nbiser    5545  0.0  0.5 121668  5296 ?        Sl   12:06   0:00 /usr/bin/akonadi_control
nbiser    5548  0.0  1.2 718828 12644 ?        Sl   12:06   0:00 akonadiserver
nbiser    5550  0.0  3.2 789160 33064 ?        Sl   12:06   0:06 /usr/sbin/mysqld --defaults-file=/home/nbiser/.local/share/akonadi/mysql.conf --datadir=/home/nbiser/.local/share/akonadi/db_d
nbiser    5590  0.0  1.7 276940 17916 ?        Sl   12:06   0:00 /usr/bin/akonadi_agent_launcher akonadi_akonotes_resource akonadi_akonotes_resource_0
nbiser    5591  0.0  1.7 270476 17916 ?        Sl   12:06   0:00 /usr/bin/akonadi_agent_launcher akonadi_contacts_resource akonadi_contacts_resource_0
nbiser    5592  0.0  1.9 273112 20168 ?        Sl   12:06   0:00 /usr/bin/akonadi_agent_launcher akonadi_ical_resource akonadi_ical_resource_0
nbiser    5593  0.0  1.8 276912 18396 ?        Sl   12:06   0:00 /usr/bin/akonadi_agent_launcher akonadi_maildir_resource akonadi_maildir_resource_0
nbiser    5594  0.0  2.1 309064 21776 ?        S    12:06   0:00 /usr/bin/akonadi_maildispatcher_agent --identifier akonadi_maildispatcher_agent
This option shows more information. I can't go into this in depth, but the %CPU and %MEM columns show the amount of CPU and RAM that is being used. The last tool that I will cover for looking at processes is the top command. It shows a live view of the processes being run:
Code:
 PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND                                                                                                                          
  633 root      20   0  229m  60m  18m S   1.0  6.0   2:13.00 Xorg                                                                                                                             
17045 nbiser    20   0  504m  32m  17m S   0.7  3.3   0:10.66 konsole                                                                                                                          
  590 root      20   0  148m 3464 3128 S   0.3  0.3   0:24.19 vmtoolsd                                                                                                                         
 3954 nbiser    20   0  616m  53m  33m S   0.3  5.4   0:46.95 kwin                                                                                                                             
 5483 nbiser    20   0  219m  18m  14m S   0.3  1.9   0:33.32 vmtoolsd                                                                                                                         
    1 root      20   0 43608 2976 1988 S   0.0  0.3   0:02.49 systemd                                                                                                                          
    2 root      20   0     0    0    0 S   0.0  0.0   0:00.01 kthreadd                                                                                                                         
    3 root      20   0     0    0    0 S   0.0  0.0   0:00.40 ksoftirqd/0                                                                                                                      
    6 root      rt   0     0    0    0 S   0.0  0.0   0:00.00 migration/0                                                                                                                      
    7 root      -2   0     0    0    0 S   0.0  0.0   0:18.07 rcuc/0                                                                                                                           
    8 root      rt   0     0    0    0 S   0.0  0.0   0:00.00 rcun/0                                                                                                                           
    9 root      -2   0     0    0    0 S   0.0  0.0   0:00.00 rcub/0                                                                                                                           
   10 root      rt   0     0    0    0 S   0.0  0.0   0:00.00 rcun/1                                                                                                                           
   11 root      -2   0     0    0    0 S   0.0  0.0   0:00.00 rcub/1                                                                                                                           
   12 root      rt   0     0    0    0 S   0.0  0.0   0:02.10 watchdog/0                                                                                                                       
   13 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 cpuset                                                                                                                           
   14 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 khelper                                                                                                                          
   15 root      20   0     0    0    0 S   0.0  0.0   0:00.00 kdevtmpfs                                                                                                                        
   16 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 netns                                                                                                                            
   17 root      20   0     0    0    0 S   0.0  0.0   0:00.10 sync_supers                                                                                                                      
   18 root      20   0     0    0    0 S   0.0  0.0   0:00.00 bdi-default                                                                                                                      
   19 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kintegrityd                                                                                                                      
   20 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kblockd                                                                                                                          
   21 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 ata_sff                                                                                                                          
   22 root      20   0     0    0    0 S   0.0  0.0   0:00.00 khubd                                                                                                                            
   23 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 md                                                                                                                               
   24 root      20   0     0    0    0 S   0.0  0.0   0:00.00 khungtaskd                                                                                                                       
   25 root      20   0     0    0    0 S   0.0  0.0   0:01.37 kswapd0                                                                                                                          
   26 root      25   5     0    0    0 S   0.0  0.0   0:00.00 ksmd                                                                                                                             
   27 root      39  19     0    0    0 S   0.0  0.0   0:01.79 khugepaged                                                                                                                       
   28 root      20   0     0    0    0 S   0.0  0.0   0:00.00 fsnotify_mark                                                                                                                    
   29 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 crypto                                                                                                                           
   33 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kthrotld                                                                                                                         
   35 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kpsmoused                                                                                                                        
   37 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 deferwq                                                                                                                          
   72 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 kmpath_rdacd                                                                                                                     
  126 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 mpt_poll_0                                                                                                                       
  127 root       0 -20     0    0    0 S   0.0  0.0   0:00.00 mpt/0                                                                                                                            
  129 root      20   0     0    0    0 S   0.0  0.0   0:00.00 scsi_eh_0                                                                                                                        
  131 root      20   0     0    0    0 S   0.0  0.0   0:01.53 kworker/u:2                                                                                                                      
  194 root      20   0     0    0    0 S   0.0  0.0   0:00.85 jbd2/sda2-8
(please note: the output was shortened)

Top is probably better than ps because it shows the processes that are being run in real time, thus giving a better idea of the processes that are using up the most RAM and CPU time.

We can now move on to ending processes.

If you need to end a process use ps or top to determine the PID, you then type this command:
Code:
kill -s sigkill pid
This will end the process immediately.

We now come to redirecting text. Lets say that use use the command ps -e, but the output is too long to display on the screen. To get around this problem you need to type:
Code:
ps -e >example.txt
This will redirect the output a .txt file.

To create a directory you need to type
Code:
mkdir directoryname
This will make the specified directory.

Finally, we come to removing files and directories. Lets say that you have a file named ezyremove.txt, and you wish to remove it. To do so you should tyep:
Code:
rm ezyremove.txt
This will permanently erase your file: you won't be able to recover it.

To erase a directory your need to type
Code:
rmdir exampledirectory
which will completely erase the directory and its contents.
Posted in Uncategorized
Views 1504 Comments 1
« Prev     Main     Next »
Total Comments 1

Comments

  1. Old Comment
    Thanks again.!!!
    Posted 06-20-2013 at 10:23 AM by vmccord vmccord is offline
 

  



All times are GMT -5. The time now is 10:10 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration