NOTE: In the examples below, lines starting with a $ are the actual commands, lines starting with a # are my comments and all other lines are the output of commands.
1. nl - Prints the file to stdout with line numbers prepended.
It’s useful if you want to search for a specific line number without opening a full text editor (like vi or emacs) and then searching for a line number. Just specifying the filename as an argument will make nl output all the contents of the file with line numbers, you can use grep to filter out the lines you need.
Syntax: nl [OPTION]… [FILE]…
Example:
$ nl hello.txt
1 Hello World
2 This is a test
2. pgrep and Pkill – Searches for or signals the processes based on their names.
These commands are really useful for system administrators, suppose you wish to search for a process and get it’s pid. The normal way any user would do it will be to use “ps aux” and then pipe it through “grep” or simply use “ps -C process-name -o pid=”. To avoid this, you can simply use the “pgrep” command to search for a process’ pid and then use the “pkill” to kill it or send a signal to it. The best thing is that “pgrep” and “pkill” use patterns to match the process names, so you can search for or send signal to multiple processes at once.
Syntax:
pgrep [OPTIONS] [PATTERN]
pkill [OPTIONS] [PATTERN]
Example:
$ pgrep vim
2747
$ pkill vim
3. pstree - Shows the process tree for the current user.
“pstree” can be used for system administration tasks. Like, if you wish to see which process was started by what program, then this command will be useful.
Syntax: pstree [OPTIONS] [PID] [USER]
Example:
$ pstree # Shows all running processes for the current user
$ pstree 2747 # Shows the process tree for the pid specified
kdm───startkde─┬─kwrapper4
└─ssh-agent
4. watch – Runs a command repeatedly and shows the output.
The basic idea behind this command is that it executes a command after a specified time period repeatedly. This can be used to monitor the output of a command. This command can be very helpful when monitoring files that change frequently, like log files. Options like “-d” can be specified to highlight the differences between successive updates.
Syntax: watch [OPTIONS]
Example:
$ watch cat hello.txt
5. lshw – Shows detailed hardware information about the system.
It’s recommended to be run as root as it needs to extract system information that needs root privileges. You can also generate HTML or XML output using the “-html” or “-xml” options. You can also specify options to show hardware information only about a specific class, like memory, processor etc. For a list of classes just use “lshw -short”.
Syntax: lshw [OPTIONS]
Example:
$ lshw -C display # Gives information only about the display.
*-display
description: VGA compatible controller
product: G92 [GeForce 9800 GT]
vendor: nVidia Corporation
physical id: 0
bus info: pci@0000:01:00.0
version: a2
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress bus_master cap_list rom
configuration: driver=nvidia latency=0
resources: irq:16 memory:d2000000-d2ffffff memory:c0000000-cfffffff(prefetchable) memory:d0000000-d1ffffff ioport:9000(size=128) memory:d3000000-d301ffff(prefetchable)
6. wc – “wc” stands for Word Count.
As the name suggests, it counts all the words in a file. It can not only count words, but it can count lines and characters as well :P Very useful for finding the size of a file in terms of lines, words or characters.
Syntax: wc [OPTIONS] [FILE]
Example:
$ wc hello.txt
2 6 27 hello.txt
7. split – Splits large files into smaller parts.
Useful for making backups or sending large files by email.
Syntax: split [OPTIONS] [INPUT] [PREFIX]
Example:
$ split -b 1M bigfile.tar.gz bigfile_ # This will split bigfile.tar.gz into files with size 1MB and prefix the splitted files with "bigfile_"
8. ldd – Shows library dependencies.
This command is useful if you have a compiled program and you wish to see which libraries it depends on. Very useful for packagers that need to specify the package dependencies.
Syntax: ldd [OPTIONS] [FILE]
Example:
$ ldd /usr/bin/aptitude
linux-gate.so.1 => (0x00d33000)
libapt-pkg-libc6.10-6.so.4.8 => /usr/lib/libapt-pkg-libc6.10-6.so.4.8 (0x00110000)
libncursesw.so.5 => /lib/libncursesw.so.5 (0x003bc000)
libsigc-2.0.so.0 => /usr/lib/libsigc-2.0.so.0 (0x00c0c000)
libcwidget.so.3 => /usr/lib/libcwidget.so.3 (0x00d79000)
libept.so.0 => /usr/lib/libept.so.0 (0x004e6000)
libxapian.so.15 => /usr/lib/libxapian.so.15 (0x00697000)
libz.so.1 => /lib/libz.so.1 (0x0092e000)
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0x00201000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x0021a000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0x00e89000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x001db000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x00943000)
libutil.so.1 => /lib/tls/i686/cmov/libutil.so.1 (0x001fa000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x00f01000)
/lib/ld-linux.so.2 (0x00b52000)
9. chardet – Shows file encoding.
It tries to guess which type of encoding a file uses and then prints the encoding name along with the filename to the terminal.
Syntax: chardet [OPTIONS] [FILE]
Example:
$ chardet /etc/resolv.conf
/etc/resolv.conf: ascii (confidence: 1.00)
10. chattr and lsattr – Changes or lists the file attributes.
“chattr” changes file attributes, the attributes are mainly file system attributes that define properties of the file. To see attributes set for a file, use “lsattr”.
Syntax:
chattr [OPTIONS] [+-=modes] [FILE]
lsattr [OPTIONS] [FILES]
Example:
$ chattr +e hello.txt
$ lsattr hello.txt
-----------------e- hello.txt
No comments:
Post a Comment