64
votes

Following in the spirit of Hidden Features of PowerShell and various others on Stack Overflow, what Linux commands or combinations of commands do you find essential in your work?

Also See:
Hidden Features of MySQL
Hidden Features of PowerShell
Hidden features of Oracle Database
Hidden Features of Windows 2008
Hidden Features of Solaris/OpenSolaris
Hidden Features of SQL Server
Hidden Features of IIS (6.0 / 7.0)

54 Answers 54

1
2
3
votes

history - shows last used commands
!<number> - executes the command with that number in history

2
votes

I'm not sure if I am just displaying my ignorance but I just found out about the "last" command for check who has been logging in. It is very useful.

Another good program is "expect". I makes it extremely easy to automate any ssh/telnet logins or anything that forces you to provide input to a program.

2
  • Using SSH keys to do automated logins is much more preferred
    – raspi
    May 28, 2009 at 0:53
  • it is but when you can't modify the allowed ssh keys on the box you have to use something like expect
    – bowman
    May 28, 2009 at 4:05
2
votes

find <blah> -exec <blah> {} \;

e.g.:

find . -iname *20080[123456].log -a ! -iname *.bz2 -exec bzip2 \{\} \;

2
  • -exec is useful, but "xargs" gives better performance. More details of the comparison here: dmiessler.com/blog/linux-xargs-vs-exec
    – Coops
    Jun 6, 2009 at 14:10
  • Important: for find+xarg, always use find with -print0, and xargs with -0. Otherwise you can have extremely nasty surprises.
    – niXar
    Sep 23, 2009 at 9:56
2
votes

bash history - I normally have 10 or so xterms running. Here is the relavent part of my profile:

# Make history ignore dups, ls, and exit
export HISTIGNORE="&:ls:[bf]g:exit"

# Save 100000 history comamnds
export HISTSIZE=10000

# Make each terminal use a separate history file
HISTDIR=${HOME}/.history
SHELLID=$(tty | sed 's!/!.!g')
HISTFILE=${HISTDIR}/history${SHELLID}

touch ${HISTFILE}

# load last histfile as current history
history -r $(/bin/ls ${HISTDIR}/history${SHELLID} | /usr/bin/tail -n 1)

If I need to search for a command, I can just grep through my history directory.

aespipe - reads from standard input and writes to standard output. It can be used to create and restore encrypted tar or cpio archives.

2
votes

logger lets you write messages to syslog from the shell prompt or a script.

logger "See? There! It happened again!"
1
  • I just discovered this today Dec 11, 2011 at 14:07
2
votes

A post that I have made on Stack Overflow: How to list only subdirectories in the current one?

ls -d */

It's a simple trick, but you wouldn't know how much time I needed to find that one!

2
votes

Usually people run their desktop system with X. But you can usually access true text-mode terminal, several of them actually. These are called virtual consoles. You can then normally login and use command-line, etc.

Just hit Ctrl + Alt + F1, Ctrl + Alt + F2, etc. Your X-server is generally running at Ctrl + Alt + F7.

This of course is distribution and configuration dependent.

Also this command to kill the X-server is sometimes useful: Ctrl + Alt + Backspace.

These key combinations work at least on i86 PC's.

1
1
vote

I find the whereis and which commands handy. Use these when you have alternative versions of the same application with the same name and want to use a specific one of them.

1
vote
scp

I'm a web dev and our development setup requires me to push files over to our dev server all the time. I wrote a quick wrapper around scp to handle this for me.

2
  • 1
    I don't think that scp is a hidden feature; it's more like the standard way of pushing files from box to box without nfs.
    – Kevin M
    Jun 26, 2009 at 15:41
  • I would recommend using sftp instead of scp for scripting. Scp has some weird behaviour with space in filenames.
    – niXar
    Sep 23, 2009 at 9:58
1
vote

The power and flexibility of SSH never cease to amaze me. Also the ability to make a raid array out of anything (floppies, anyone?), all the filesystems available, cool stuff like LVM, the crypto tools, the possibility of crafting your own tools with the myriad of compilers, interpreters, languages... Oh, and not forgetting getting new stuff installed with apt-get or similar.

It is just so much brilliant than windows.

1
vote
lsof -i - list all opened socket
htop - like top, but with more eye candy
rdiff-backup - for incremental backup
mc - midnight commander 
ethstatus - ethernet statistics
netstat, nmap
iftop - display bandwidth usage on an interface by host
1
vote

NX combines some of the benefits of screen and ssh -X with clever compression. Now I can run gnumeric remotely over a modem connection and resume it when the connection dies.

1
  • Could you give an example on how to use NX as a straight replacement for ssh -X? I don't care for the remote desktop thing, just want to be able to run short-lived apps over a slow connection. The desktop thing is such a bear to config.
    – niXar
    Sep 23, 2009 at 9:55
1
vote

fgrep

e.g. fgrep -r * --include=*.rb

walks the dir structure from the current directory looking for in ruby source files

and is much easier to use than find

2
  • ack is another interesting tool for searching in files. It ignores version control files (like .svn -directories) by default and you can tell it to only search in ruby source etc.
    – ptman
    May 23, 2010 at 17:38
  • It may be easier on first glance, but, find is much more powerful, and, worth getting to know. find . -type f -name "*.rb" -exec grep <pattern to find> {} \; Jan 19, 2011 at 15:21
1
vote

dd - convert and copy files

I use this very frequently to make copys of DVD's or HDD Patitions that I need to backup.

dd if=/dev/sda2 of=/tmp/copy_of_sda2

it's very handy and configurable, just have a look at it's man page

1
vote

POSIX Capabilities & File POSIX Capabilities

http://www.friedhoff.org/posixfilecaps.html

1
vote

For "hidden" feature as in most often overlooked or missed by users new to Linux (/Unix).

  • man man
  • man -k <blah> or apropos <blah>

"Hidden" features

1
vote

My top 5 "hidden" features (hopefully these aren't already up here)

  1. cd - try it out :)
  2. named pipes are not used enough and you can do some really cool stuff with them
  3. system tap, although I'm not great at it and you really need to know your kernel it wields incredible power to the right user.
  4. The combination of piping a list to sort, then to uniq -c and then to sort -n can really work wonders. You can use that to get your top talkers out of an Apache log file or the memory hogs from ps -o.
  5. The proc/sys interface/filesystem. There is so much there that you can adjust/view in real time. Wrapping a cat or grep of statement in watch -d -n 0.1 is awesome and very handy.

Notables are dd, netcat, screen, tcpdump and find but most have been mentioned already.

0
votes
  • man (gives help on most commands)
  • less (sanely browseable viewing)
  • tail -f (view appended data of a file as it grows)
  • watch (execute a program and view its output periodically full-screen)
6
  • I find /usr/bin/most even better than less. Excellent syntax highlighting, among other things. May 9, 2009 at 20:56
  • 7
    tail -F is better than -f; it notices if a file is rotated
    – niXar
    May 29, 2009 at 9:57
  • @Matthew: I don't get any syntax highlighting in most by itself, nor do I see any reference to it in the docs. Feb 5, 2010 at 3:01
  • @Dennis, try PAGER=most man ls Feb 10, 2010 at 18:13
  • @Matthew: That's not syntax highlighting. That's colorization. You can colorize less (including for man pages) by setting the LESS_TERMCAP_* variables. If most prog.c worked, that would be syntax highlighting. Feb 10, 2010 at 19:59
0
votes

I simply can't do without these commands

  • ps -fA (list all running programs
  • lsof (list of open files per process)
  • pushd . (push current directory onto the directory stack)
  • popd . (pop current directory from the directory stack)
  • local account home directory ~/ you can also access a user directory like ~username.
  • replace current bash profile after you've made changes without logging back in. ". ~/.bashrc
  • grep -inR (recursive grep, i = case insensitive, n = show like number, R = recursive)
0
votes

ctrl + r : searches history for the last command with the letters you specify

0
votes

Let's see ...

  • I use bash color codes in my /root/.bash_profile to make my root bash prompt a different color than my non-root standard user prompt. Just one more reminder that I'm a single command away from destroying an entire system. ;)

  • I use nc (netcat) a lot to test things. Nice utility with a lot of versatility.

  • For the longest time I never knew that chown could accept both username and groupname together as an argument, i.e.: chown user:group -R /some/directory. That fact has saved me a lot of typing (no more chown/chgrp pairs).

  • The df command's a quick shortcut to see all your mounted filesystems.

  • I use pgrep a lot in scripts to see if a process is running.

  • kexec is pretty neat, lets you reboot without going through BIOS, which shortens reboot times significantly. Don't really reboot a lot, though...

1
  • Did you know you can chown user: without a specific group, and, the group will be assigned as the default group of the user specified. Jan 19, 2011 at 15:17
0
votes

find is my greatest tool. I use it to locate things, and execute commands on files or directories found.

No system is complete without ssh too.

0
votes

Never used script(1) to save a terminal session?
apg(1) to make random passwords
do you want to know how many processors/cores you have? nproc(1)
sfdisk(8) great partition tool
multitail(1) multiple tail at once...great tool

0
votes

For me, the greatest feature is that nothing is really "hidden" - it's all there right under your eyes if you bother to read the documentation or code.

1
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .