25 Best Linux Commands

As a Linux user you’ll come to learn and love certain commands. Remembering these commands is the toughest part.

Some people use cheat-sheets, some create scripts, and some just refer to website for their fix. Here I have posted the 25 top command line snippets. Please remember to always read man pages for any command before running any commands or applications

25) sshfs name@server:/path/to/folder /path/to/mount/point
Mount folder/filesystem through SSH
Install SSHFS from http://fuse.sourceforge.net/sshfs.html
Will allow you to mount a folder security over a network.

24) !!:gs/foo/bar
Runs previous command replacing foo by bar every time that foo appears
Very useful for rerunning a long command changing some arguments globally.
As opposed to ^foo^bar, which only replaces the first occurrence of foo, this one changes every occurrence.

23) mount | column -t
currently mounted filesystems in nice layout
Particularly useful if you’re mounting different drives, using the following command will allow you to see all the filesystems currently mounted on your computer and their respective specs with the added benefit of nice formatting.

22) <space>command
Execute a command without saving it in the history
Prepending one or more spaces to your command won’t be saved in history.
Useful for pr0n or passwords on the commandline.

21) ssh user@host cat /path/to/remotefile | diff /path/to/localfile –
Compare a remote file with a local file
Useful for checking if there are differences between local and remote files.

20) mount -t tmpfs tmpfs /mnt -o size=1024m
Mount a temporary ram partition
Makes a partition in ram which is useful if you need a temporary working space as read/write access is fast.
Be aware that anything saved in this partition will be gone after your computer is turned off.

19) dig +short txt <keyword>.wp.dg.cx
Query Wikipedia via console over DNS
Query Wikipedia by issuing a DNS query for a TXT record. The TXT record will also include a short URL to the complete corresponding Wikipedia entry.

18) netstat -tlnp
Lists all listening ports together with the PID of the associated process
The PID will only be printed if you’re holding a root equivalent ID.

17) dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
output your microphone to a remote computer’s speaker
This will output the sound from your microphone port to the ssh target computer’s speaker port. The sound quality is very bad, so you will hear a lot of hissing.

16) echo “ls -l” | at midnight
Execute a command at a given time
This is an alternative to cron which allows a one-off task to be scheduled for a certain time.



15) curl -u user:pass -d status=”Tweeting from the shell” http://twitter.com/statuses/update.xml
Update twitter via curl

14) ssh -N -L2001:localhost:80 somemachine
start a tunnel from some machine’s port 80 to your local post 2001
now you can acces the website by going to http://localhost:2001/

13) reset
Salvage a borked terminal
If you bork your terminal by sending binary data to STDOUT or similar, you can get your terminal back using this command rather than killing and restarting the session. Note that you often won’t be able to see the characters as you type them.

12) ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg
Capture video of a linux desktop

11) > file.txt
Empty a file
For when you want to flush all content from a file without removing it (hat-tip to Marc Kilgus).

10) $ssh-copy-id user@host
Copy ssh keys to user@host to enable password-less ssh logins.
To generate the keys use the command ssh-keygen

9) ctrl-x e
Rapidly invoke an editor to write a long, complex, or tricky command
Next time you are using your shell, try typing ctrl-x e (that is holding control key press x and then e). The shell will take what you’ve written on the command line thus far and paste it into the editor specified by $EDITOR. Then you can edit at leisure using all the powerful macros and commands of vi, emacs, nano, or whatever.

8 ) !whatever:p
Check command history, but avoid running it
!whatever will search your command history and execute the first command that matches ‘whatever’. If you don’t feel safe doing this put :p on the end to print without executing. Recommended when running as superuser.

7) mtr google.com
mtr, better than traceroute and ping combined
mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.
As mtr starts, it investigates the network connection between the host mtr runs on and HOSTNAME. by sending packets with purposly low TTLs. It continues to send packets with low TTL, noting the response time of the intervening routers. This allows mtr to print the response percentage and response times of the internet route to HOSTNAME. A sudden increase in packetloss or response time is often an indication of a bad (or simply over‐loaded) link.

6 ) cp filename{,.bak}
quickly backup or copy a file with bash

5) ^foo^bar
Runs previous command but replacing
Really useful for when you have a typo in a previous command. Also, arguments default to empty so if you accidentally run:
echo “no typozs”
you can correct it with
^z

4) cd –
change to the previous working directory

3):w !sudo tee %
Save a file you edited in vim without the needed permissions
I often forget to sudo before editing a file I don’t have write permissions on. When you come to save that file and get the infamous “E212: Can’t open file for writing”, just issue that vim command in order to save the file without the need to save it to a temp file and then copy it back again.

2) python -m SimpleHTTPServer
Serve current directory tree at http://$HOSTNAME:8000/

1) sudo !!
Run the last command as root
Useful when you forget to use sudo for a command. “!!” grabs the last run command.

source

That’s it people!

38 Comments

  1. Reply

    In addition to ` !whatever:p` don’t forget about using ctrl+r to do a search of your history as you type. It only returns the most recent hit, but is useful nonetheless.

  2. Jameson

    Reply

    I don’t appreciate the poor quality of information you’re contributing here. First, let’s make the distinction between ‘commands’, ‘applications’, and shell features.

    There is no such thing as “Linux command” per se. There are a wide variety of shells, and no one shell is any sort of standard beyond what specific organizations choose as standard for a particular software distribution.

    “sshfs” is an application. Yes, technically you issue a command to use it, but why would you tout it as some sort of neat command, when in reality you mean ‘a cool application’? ffmpeg, curl, mtr, dig, python, and several others. There is nothing novel to the command being performed, but rather the application you are invoking is interesting as a non-GNU project.

    Several other features assume specific shells as well.

    I’m glad you’ve discovered using the shell yourself, but don’t think you’re contributing anything to the community with this.

    • Reply

      Thank you Jameson for the heads up, and you are right. This article should have been called something like command-line gems. Also if you read the first paragraph I mention that “Here I have posted the 25 top command line snippets.”

  3. Reply

    With respect to #22, you should never put passwords in the commandline; it might not show up in your history, but you will see it if you execute “ps aux”, and hence that is not secure.

  4. Pingback: Top 25 Best Linux Commands « Netcrema – creme de la social news via digg + delicious + stumpleupon + reddit

  5. Mike

    Reply

    I dont really care much for what Jameson says. This s quite a handy guide for people starting out on the command line.

  6. Pingback: Top 25 Best Linux Commands : Popular Links : eConsultant

  7. Reply

    To Jameson..you read a post a get offended? Hahaha…what a loser. I think you have a lot of pent up stress Jameson, you should maybe buy an inflatable girlfriend to help relieve that stress since. I’m sure no woman will come within 15 feet of your sad self loathing self

  8. Reply

    To guhnoo before you accuse someone of plagiarism you should read..there is a source listed very clearly at the bottom of the post….

    To Isaiah ( the author) Love the post! Found it to be insightful and a great tool for a newbie like me :)

  9. Eoin Murphy

    Reply

    @Jason Whaley You can just hit ctrl-r again to get the next hit, and again, and again…

  10. Xephyr

    Reply

    I agree entirely with Jameson. The vast majority of these are /not/ “commands” in terms of usage of entirely [bf]?[azki]sh or the GNU coreutils. Instead, they are mostly third-party applications, such as python. sshfs in itself is quite a few non-GNU projects as dependencies! I understand that this is more or less a “babby’s first pipes” list, but c’mon. Don’t be so misleading. A better title would be “25 GNU/Linux NON-STANDARD NON-UNIX CLI-ORIENTED SNIPPETS”.

    mtr considered harmful.

  11. Pingback: Top 25 Best Linux Commands | Thats The New Thing

  12. Reply

    @Xephyr your comment makes no sense, you complain there is no edit button which just proves how ignorant you truly are, ever heard of proof reading? The post is well written your comment wasn’t, next time you think your voice matters double check because it doesn’t.

  13. Pingback: links for 2010-10-31 at DeStructUred Blog

  14. Pingback: CSS3 Slideshow and 25 Linux Commands | Chiggins' Thoughts

  15. Pingback: links for 2010-11-01 « Mandarine

  16. Jeff

    Reply

    It would be cleaner to name the source in addition to providing a link to the source. In addition it would be way cooler to explicitly thank the source.

  17. Pingback: Quickies: useful command lines « 0ddn1x: tricks with *nix

  18. Pingback: Comhack » Blog Archive » 25 Best Linux Commands

  19. Pingback: Austoon Daily » Top 25 Best Linux Commands

  20. Pingback: Daily del.icio.us for October 29th through November 3rd — Vinny Carpenter's blog

  21. Pingback: Top 25 Best Linux Commands | dev-Ops

  22. Pingback: 25 Comandos Linux « José Ricardo Ziviani

  23. Pingback: Posts Collection #1 « Dev – Blue solutions

  24. Harry

    Reply

    Isaiah,
    Thanks for sharing your knowledge. Don’t get discourage a bit by any negative comments. I for one found your post useful.

  25. Reply

    Freakin’ cool man! I have to point out that I’m always impressed when I discover new sausage of piped commands that provide some great thing, without installing specific apps for it, like that thing with ffmpeg. Awesome!

  26. Reply

    I cannot believe the response of people like Jameson. This is a very handy list that is geared towards intermediate users who can obviously tell the difference between an external application and bash builtin. I have no clue where his negativity comes from but rest assured the rest of the community appreciates this post. Props on the ffmpeg command btw. I’d also like to see a post on GNU Screen.

  27. Steve

    Reply

    Jeez, the pedants come out at night, don’t they? Who cares if they’re commands, applications or flying monkeys from the planet Arsehole? These are all really useful and I, for one, have learnt something. I’m actually going to bookmark this page for future reference.

    Despite what Jameson says, I DO think you’re helping the community with this page. Jameson is just clearly a dick :)

    (It said I double posted this, but I don’t think I did…)

  28. Pingback: Delicious Bookmarks for January 5th through January 6th « Lâmôlabs

  29. Linux Commands

    Reply

    Nice notes. There is nothing novel to the command being performed, but rather the application you are invoking is interesting.

  30. Pingback: [blog.rayfoo] » (Many) Sick Linux Commands

Leave Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.