Friday January 14, 2005 at 23:39
Subject: These are a few of my favorite commands.
Keywords:
Linux, Technical
Posted by: Sean Reifschneider
Related entries:These are a few of my favorite XDefaults. by Sean Reifschneider, Thursday January 20, 2005 at 18:44
I know there are lot of GUI tools out there, but I'm very much a
command-line person. In general I'd like to type "ls" more than to find a
file listing dialog, for example, because you can so easily do small
variations like "ls -ltr" (show files sorted by time), "ls -lSr" (sorted by
size), "ls -l | grep foo" (what file have "foo "in the name), etc. GUIs
work very well for the casual user, but they don't work as well for
frequent use. Here are some of my favorite commands and command sequences.
(Post Reply)
-
"stat" gives all sorts of information about a file or directory
including type, size, permissions, device... Want to know if
"/etc/services" is on your root file-system? Check the device number
with: "stat -c %d /etc/services /". Are you out of inodes in "/"?
"stat -f -c %d /" will tell you.
"df -i" is often overlooked when checking for full file-systems.
Often it's because of lack of data space, but if not that it's probably
because of lack of inodes.
"du -x | sort -n" will show disc usage by directory, largest
directories at the bottom.
"fuser -n tcp 80" will show the process(es) which is bound to port
80/tcp. Very handy in scripts to see if a network program is
running.
"ssh" is useful all over the place. Secure logins to remote
systems, running remote commands, scripting data transfers to other
machines. A great tool.
"rsync" is another great multi-purpose tool. Great for copying
ISO files, if you have one that's close to the one you need to copy
it can make a huge difference. Last week I updated a 200MB ISO file
to a new version over a 7KB/sec CDMA line in just a few minutes. Can
also be used to do full and incremental system backups and even act
like a file-system diff, even across machines.
"rpm -qf /path/to/file" tells you what package a file is part of.
"clear" when I'm done doing something in a window clears it so
that I can keep context around when I need it and only when I'm still
working on it.
"file" analyzes the contents of a file and tries to figure out
what type of file it is. It doesn't matter what extension the file has.
"dd" has all sorts of options for dealing with processing data to
and from files and devices. Including setting block sizes, skipping and
limiting the data copied.
"echo $[RANDOM%1024]" from the shell will randomly generate a
number below 1024, a good way to come up with a non-WKS to move SSH to so that dorks who are
hitting SSH can't find it as easily.
"mkdir -p" will recursively make a directory and all directories
above it if they don't exist.
(Post Reply)
| Comment |
Author:
Tkil Subject: a few additions |
Two more that I'd add:
-
The "-h" flag for GNU variants of 'df' and a few other commands puts the output into "human-readable" format -- it presents values in terms of KiB, MiB, or GiB (instead of 512-byte blocks, or 1024-byte blocks with "-k")
When using "rpm -qf", a very useful argument is the automatically-found path to the executable. In 'bash', that is: rpm -qf `which COMMAND`
| Comment |
Author:
Sean Reifschneider Subject: On human readable "df". |
Most Gnu tools will also look for an environment variable, so if you set "LS_BLOCK_SIZE=human-readable" in your environment the sizes for ls and df will come out human readable. There are also versions named "DF_BLOCK_SIZE" and "DU_BLOCK_SIZE".