Command Line Utilities: Difference between revisions

From Elvanör's Technical Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
This is a collection of random useful command line tools.
This is a collection of random useful command line tools.


* To obtain the space available on a HD: df -h
= Network Related =


= rsync =
== rsync ==


* --no-p: this will disable permissions synchronization.
* --no-p: this will disable permissions synchronization.
* --no-o: this will disable owner synchronization.
* --no-o: this will disable owner synchronization.


= tar =
== nmap ==
 
* This program allows you to test if a port is open on a remote box.
 
== netstat ==
 
* netstat -altp will list all the open ports on your machine, along with the process that opened it. Very useful!
 
= File & I/O =
 
* To obtain the space available on a HD: df -h
 
== tar ==


* Use the -C option to switch to a directory before compressing. Very useful.
* Use the -C option to switch to a directory before compressing. Very useful.
* Use the -h option to follow symbolic links.
* Use the -h option to follow symbolic links.


= cpio =
== cpio ==


* This seems to be something similar to tar.
* This seems to be something similar to tar.
Line 20: Line 32:
This would copy the *.txt files to another box, preserving the directory hierarchy.
This would copy the *.txt files to another box, preserving the directory hierarchy.


= gpasswd =
= Administration =
 
== gpasswd ==


* This is the command used on Gentoo to change an user's groups. You can also edit /etc/group, but this is not the right way of doing things. It will usually fail because you also need to change /etc/gshadow. Note that /etc/group- is just a backup of /etc/group.
* This is the command used on Gentoo to change an user's groups. You can also edit /etc/group, but this is not the right way of doing things. It will usually fail because you also need to change /etc/gshadow. Note that /etc/group- is just a backup of /etc/group.


= ps =
= Other =
 
== ps ==


* The legend for the status letters of processes can be found in the man page. R basically means running, and S means sleeping.
* The legend for the status letters of processes can be found in the man page. R basically means running, and S means sleeping.

Revision as of 17:45, 15 September 2008

This is a collection of random useful command line tools.

Network Related

rsync

  • --no-p: this will disable permissions synchronization.
  • --no-o: this will disable owner synchronization.

nmap

  • This program allows you to test if a port is open on a remote box.

netstat

  • netstat -altp will list all the open ports on your machine, along with the process that opened it. Very useful!

File & I/O

  • To obtain the space available on a HD: df -h

tar

  • Use the -C option to switch to a directory before compressing. Very useful.
  • Use the -h option to follow symbolic links.

cpio

  • This seems to be something similar to tar.
  • Allows you to do nice stuff like
find . -name '*.txt' print0 | cpio -o -0 | ssh elvanor@otherbox 'cd dirB && cpio -iduv -0'

This would copy the *.txt files to another box, preserving the directory hierarchy.

Administration

gpasswd

  • This is the command used on Gentoo to change an user's groups. You can also edit /etc/group, but this is not the right way of doing things. It will usually fail because you also need to change /etc/gshadow. Note that /etc/group- is just a backup of /etc/group.

Other

ps

  • The legend for the status letters of processes can be found in the man page. R basically means running, and S means sleeping.
  • Something very tricky can happen with ps: ps lists a process, but ps | grep will not. This is because if processes are always spawned and short lived (which means you have a problem on your system), ps when started on a shell will get the time to catch the process but ps | grep will run faster (less text to output) and so won't catch the process. A way to check for signs of this problem is to launch htop and see if the CPU is at 100% usage.

Tricks and tips

  • Redirecting all outputs to a file:
foo &> bar

To redirect only stderr:

foo 2> bar