Tuesday 4 September 2012

Linux miscellaneous Commands ?



3. id





The id command lists the real and effective user IDs and the group IDs of the user associated with the current process.

This is the counterpart to the $UID$EUID, and $GROUPS internal Bash variables.

bash$ id
uid=501(bozo) gid=501(bozo) groups=501(bozo),22(cdrom),80(cdwriter),81(audio)

bash$ echo $UID
501

4.lid
The lid (list ID) command shows the group(s) that a given user belongs to, or alternately, the users belonging to a given group. May be invoked only by root.


5. logname

Show current user's login name (as found in /var/run/utmp).

[sankar@new-host perlscript]$ logname
sankar
[sankar@new-host perlscript]$ whoami
sankar



Note:: While logname prints the name of the logged in user, whoami gives the name of the user attached to the current process. As we have just seen, sometimes these are not the same.
[sankar@new-host perlscript]#logname
sankar
[sankar@new-host perlscript]#whoami
root

   







6. ac
Show users' logged in time, as read from /var/log/wtmp.


[sankar@new-host perlscript]$ ac
        total       26.20

7. last
List last logged in users, as read from /var/log/wtmp.


[sankar@new-host perlscript]$ last

sankar   pts/5        :0               Tue Sep  4 11:08   still logged in
sankar   :0                            Tue Sep  4 09:30   still logged in
sankar   :0                            Tue Sep  4 09:30 - 09:30  (00:00)
xavier   pts/2        :2.0             Tue Sep  4 09:29   still logged in
root     pts/1        :1.0             Tue Sep  4 09:29   still logged in
reboot   system boot  2.6.18-194.3.1.e Tue Sep  4 09:28          (06:30)
sankar   :0                            Mon Sep  3 17:57 - 18:35  (00:38)
sankar   :0                            Mon Sep  3 17:57 - 17:57  (00:00)
xavier   pts/2        :2.0             Mon Sep  3 17:56 - down   (00:39)
root     pts/1        :1.0             Mon Sep  3 17:56 - down   (00:39)
reboot   system boot  2.6.18-194.3.1.e Mon Sep  3 17:55          (00:39)

wtmp begins Mon Sep  3 17:03:14 2012


[sankar@new-host perlscript]$ last reboot

reboot   system boot  2.6.18-194.3.1.e Tue Sep  4 09:28          (06:31)
reboot   system boot  2.6.18-194.3.1.e Mon Sep  3 17:55          (00:39)

8. newgrp
Change user's group ID without logging out. This permits access to the new group's files

    Note: a terminal works in the canonical mode.
    stty: Shows and/or changes terminal settings.



9. setterm




Set certain terminal attributes. This command writes to its terminal's stdout a string that changes the behavior of that terminal.

bash$ setterm -cursor off
bash$
       

The setterm command can be used within a script to change the appearance of text written to stdout, although there are certainly better tools available for this purpose.

setterm -bold on
echo bold hello

setterm -bold off
echo normal hello

10. tset
Show or initialize terminal settings. This is a less capable version of stty.

bash$ tset -r
Terminal type is xterm-xfree86.
 Kill is control-U (^U).
 Interrupt is control-C (^C).
       

11. setserial
Set or display serial port parameters. This command must be run by root and is usually found in a system setup script.

# From /etc/pcmcia/serial script:

IRQ=`setserial /dev/$DEVICE | sed -e 's/.*IRQ: //'`
setserial /dev/$DEVICE irq 0 ; setserial /dev/$DEVICE irq $IRQ

12. gettyagetty
The initialization process for a terminal uses getty or agetty to set it up for login by a user. These commands are not used within user shell scripts. Their scripting counterpart is stty.

13. mesg
Enables or disables write access to the current user's terminal. 



14. arch
Show system architecture. Equivalent to uname -m.


15. lastcomm
Gives information about previous commands, as stored in the /var/account/pacct file.

16. lastlog
List the last login time of all system users. This references the /var/log/lastlog file.

17. strace
System trace: diagnostic and debugging tool for tracing system calls and signals. This command and ltrace(ltrace - A library call tracer)



18. nc
The nc (netcat) utility is a complete toolkit for connecting to and listening to TCP and UDP ports. It is useful as a diagnostic and testing tool and as a component in simple script-based HTTP clients and servers.
  $ nc localhost.localdomain 25
    220 localhost.localdomain ESMTP Sendmail 8.13.1/8.13.1;
      Thu, 31 Mar 2005 15:41:35 -0700

19. procinfo
Extract and list information and statistics from the /proc pseudo-filesystem
     $ procinfo | grep Bootup
     Bootup: Wed Mar 21 15:15:50 2001    Load average: 0.04 0.21 0.34 3/47 6829

20. lsdev
List devices, that is, show installed hardware.

$ lsdev
Device            DMA   IRQ  I/O Ports
 ------------------------------------------------
 cascade             4     2 
 dma                          0080-008f
 dma1                         0000-001f
 dma2                         00c0-00df
 fpu                          00f0-00ff
 ide0                     14  01f0-01f7 03f6-03f6
 ...

21. du
Show (disk) file usage, recursively. Defaults to current working directory, unless otherwise specified.

$ du -ach
1.0k    ./wi.sh
 1.0k    ./tst.sh
 1.0k    ./random.file
 6.0k    .
 6.0k    total

22. stat
Gives detailed and verbose statistics on a given file (even a directory or device file) or set of files.

$ stat test.cru
  File: "test.cru"
   Size: 49970        Allocated Blocks: 100          Filetype: Regular File
   Mode: (0664/-rw-rw-r--)         Uid: (  501/ bozo)  Gid: (  501/ bozo)
 Device:  3,8   Inode: 18185     Links: 1    
 Access: Sat Jun  2 16:40:24 2001
 Modify: Sat Jun  2 16:40:24 2001
 Change: Sat Jun  2 16:40:24 2001

23. $ ps a | grep mingetty
2212 tty2     Ss+    0:00 /sbin/mingetty tty2
 2213 tty3     Ss+    0:00 /sbin/mingetty tty3
 2214 tty4     Ss+    0:00 /sbin/mingetty tty4
 2215 tty5     Ss+    0:00 /sbin/mingetty tty5
 2216 tty6     Ss+    0:00 /sbin/mingetty tty6
 4849 pts/2    S+     0:00 grep mingetty


bash$ pgrep mingetty
2212 mingetty
 2213 mingetty
 2214 mingetty
 2215 mingetty
 2216 mingetty

24. pstree
Lists currently executing processes in "tree" format. The -p option shows the PIDs, as well as the process names.

25. fuser
Identifies the processes (by PID) that are accessing a given file, set of files, or directory.

26. telinit
Symlinked to init, this is a means of changing the system runlevel, usually done for system maintenance or emergency filesystem repairs.

27. iwconfig
This is the command set for configuring a wireless network. It is the wireless equivalent of ifconfig, above.

    A netstat -lptu shows sockets that are listening to ports,


28. losetup



Sets up and configures loopback devices.

29. mkdosfs
Create a DOS FAT filesystem.

30. fscke2fsckdebugfs
Filesystem check, repair, and debug command set.

31. lsusbusbmodules

The lsusb command lists all USB (Universal Serial Bus) buses and the devices hooked up to them.
The usbmodules command outputs information about the driver modules for connected USB devices.
$ lsusb
Bus 001 Device 001: ID 0000:0000  
 Device Descriptor:
   bLength                18
   bDescriptorType         1
   bcdUSB               1.00
   bDeviceClass            9 Hub
   bDeviceSubClass         0 
   bDeviceProtocol         0 
   bMaxPacketSize0         8
   idVendor           0x0000 
   idProduct          0x0000

   . . .

32. lockfile
This utility is part of the procmail package (www.procmail.org). It creates a lock file, a semaphore that controls access to a file, device, or resource.
flock
Much less useful than the lockfile command is flock. It sets an "advisory" lock on a file and then executes a command while the lock is on.

33. mknod
Creates block or character device files (may be necessary when installing new hardware on the system). The MAKEDEV utility has virtually all of the functionality of mknod, and is easier to use.

34. MAKEDEV
Utility for creating device files. It must be run as root, and in the /dev directory. It is a sort of advanced version of mknod.

35. tmpwatch
Automatically deletes files which have not been accessed within a specified period of time.

System Resources
36. ulimit
Sets an upper limit on use of system resources. Usually invoked with the -f option, which sets a limit on file size (ulimit -f 1000 limits files to 1 meg maximum). [7] The -t option limits the coredump size (ulimit -c 0 eliminates coredumps). Normally, the value of ulimit would be set in /etc/profileand/or ~/.bash_profile

37. ldd
Show shared lib dependencies for an executable file.
$ ldd /bin/ls
libc.so.6 => /lib/libc.so.6 (0x4000c000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)

38. watch
Run a command repeatedly, at specified time intervals.
The default is two-second intervals, but this may be changed with the -n option.

watch -n 5 tail /var/log/messages
# Shows tail end of system log, /var/log/messages, every five seconds.




39. strip
         strip modifies the files named in its argument, rather than  writing  modified  copies  under  different names.


40.vol_id - probe filesystem type and read label and uuid.


vol_id supports
       all common filesystem formats and detects various raid setups.vol_id is usually called from a udev rule 

OPTIONS
       --export
              print all values in key/value format to import them into the
              environment.

       -t     print the filesystem type

       -l     print the label of a volume
-u     print the uuid of a volume

41. bash$ ps a | grep mingetty
2212 tty2     Ss+    0:00 /sbin/mingetty tty2
 2213 tty3     Ss+    0:00 /sbin/mingetty tty3
 2214 tty4     Ss+    0:00 /sbin/mingetty tty4
 2215 tty5     Ss+    0:00 /sbin/mingetty tty5
 2216 tty6     Ss+    0:00 /sbin/mingetty tty6
 4849 pts/2    S+     0:00 grep mingetty


42. bash$ pgrep mingetty
2212 mingetty
 2213 mingetty
 2214 mingetty
 2215 mingetty
 2216 mingetty

43. pstree
Lists currently executing processes in "tree" format. The -p option shows the PIDs, as well as the process names.

44. pidof
Identifies process ID (PID) of a running job. Since job control commands,


sankar@new-host ~]$ /sbin/pidof chrome
12322 11382 8787 8301 7375 6771 6737 6713 6712 6707

45. fuser
Identifies the processes (by PID) that are accessing a given file, set of files, or directory.


[sankar@new-host ~]$ /sbin/fuser -u /usr/bin/vim
/usr/bin/vim:        13042e(sankar)

     bash$ fuser -u /dev/null
     /dev/null:            3009(bozo)  3010(bozo)  3197(bozo)  3199(bozo)

bash$ fuser -um /dev/usbdrive
/mnt/usbdrive: 1772c(bozo)

root# fuser -un tcp 25
    25/tcp:               2095(root)
      The fuser command, invoked with the -n option identifies the processes accessing a port

46. hdparm
List or change hard disk parameters. This command must be invoked as root, and it may be dangerous if misused.

47. lsusb
     The lsusb command lists all USB (Universal Serial Bus) buses and the devices hooked up to them.

[sankar@new-host ~]$ /sbin/lsusb
Bus 002 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 003 Device 002: ID 04f3:0230 Elan Microelectronics Corp.
Bus 001 Device 001: ID 0000:0000
Bus 005 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
------------------------
bash$ lsusb
Bus 001 Device 001: ID 0000:0000  
 Device Descriptor:
   bLength                18
   bDescriptorType         1
   bcdUSB               1.00
   bDeviceClass            9 Hub
   bDeviceSubClass         0 
   bDeviceProtocol         0 
   bMaxPacketSize0         8
   idVendor           0x0000 
   idProduct          0x0000

48. lspci
Lists pci busses present.


[sankar@new-host ~]$ /sbin/lspci
00:00.0 Host bridge: Intel Corporation 82865G/PE/P DRAM Controller/Host-Hub Interface (rev 02)
00:02.0 VGA compatible controller: Intel Corporation 82865G Integrated Graphics Controller (rev 02)
00:1d.0 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #1 (rev 02)
00:1d.1 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #2 (rev 02)
00:1d.2 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #3 (rev 02)
00:1d.3 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #4 (rev 02)
00:1d.7 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB2 EHCI Controller (rev 02)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev c2)
00:1f.0 ISA bridge: Intel Corporation 82801EB/ER (ICH5/ICH5R) LPC Interface Bridge (rev 02)
00:1f.1 IDE interface: Intel Corporation 82801EB/ER (ICH5/ICH5R) IDE Controller (rev 02)
00:1f.2 IDE interface: Intel Corporation 82801EB (ICH5) SATA Controller (rev 02)
00:1f.3 SMBus: Intel Corporation 82801EB/ER (ICH5/ICH5R) SMBus Controller (rev 02)
00:1f.5 Multimedia audio controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) AC'97 Audio Controller (rev 02)
01:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 10)


49. mknod
Creates block or character device files (may be necessary when installing new hardware on the system). The MAKEDEV utility has virtually all of the functionality of mknod, and is easier to use.

50. tmpwatch
Automatically deletes files which have not been accessed within a specified period of time. Usually invoked by cron to remove stale log files.

51. ulimit
Sets an upper limit on use of system resources.
          Normally, the value of ulimit would be set in /etc/profileand/or ~/.bash_profile.

52. ldd
Show shared lib dependencies for an executable file.
bash$ ldd /bin/ls
libc.so.6 => /lib/libc.so.6 (0x4000c000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)

     






No comments:

Post a Comment