Question

What are your favorite command line tips or tricks?

In the same vein as my previous question about bash aliases, what are your favorite command line tricks? What command has saved you the most time? What bash features did you never realize existed and now use daily and can’t live without?

Of course, there are the classics:

  • !! - Re-runs the last command you entered
  • sudo !! - Re-runs the last command you entered as a super user

What are yours? (No cheating.)

Subscribe
Share

Just typed calendar in Ubuntu, it brought a list of major events in history that happened today. Good general knowledge.

Just typed calendar in Ubuntu, it brought a list of major events in history that happened today. Good general knowledge.

You can even use sed (I think) to alter the command:

!!:s/foo/bar

@m1025 Forgot about calendar! Nice shout out.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

https://mosh.org/ instead of SSH! http://ohmyz.sh/ with several plugins.

A good one is: find . -type f -iname "*.something" -del; which recursively finds and deletes files. find has many neat tricks and is a good one to have handy.

du for disk usage, along with the --max-depth and -h flags will give you a nice overview if you are trying to find what is taking up space. -c will give you a grand total at the end.

  • rsync for moving stuff
  • wget is great (especially with the -c (continue) flag)
  • gnu parallel for running batch jobs in…parallel
  • flock for making sure your cron job is only running one instance at any given time
  • the $() for getting the output from a command that was mentioned earlier is great, and you can also
  • I’m not sure where exactly it comes from, I think it ships with perl in deb-based distros, but the rename command is great for bulk-renaming jobs
  • rsync for moving stuff
  • wget is great (especially with the -c (continue) flag)
  • gnu parallel for running batch jobs in…parallel
  • flock for making sure your cron job is only running one instance at any given time
  • the $() for getting the output from a command that was mentioned earlier is great, and you can also
  • I’m not sure where exactly it comes from, I think it ships with perl in deb-based distros, but the rename command is great for bulk-renaming jobs
  • rsync for moving stuff
  • wget is great (especially with the -c (continue) flag)
  • gnu parallel for running batch jobs in…parallel
  • flock for making sure your cron job is only running one instance at any given time
  • the $() for getting the output from a command that was mentioned earlier is great, and you can also
  • I’m not sure where exactly it comes from, I think it ships with perl in deb-based distros, but the rename command is great for bulk-renaming jobs
  • rsync for moving stuff
  • wget is great (especially with the -c (continue) flag)
  • gnu parallel for running batch jobs in…parallel
  • flock for making sure your cron job is only running one instance at any given time
  • the $() for getting the output from a command that was mentioned earlier is great, and you can also
  • I’m not sure where exactly it comes from, I think it ships with perl in deb-based distros, but the rename command is great for bulk-renaming jobs
  • rsync for moving stuff
  • wget is great (especially with the -c (continue) flag)
  • gnu parallel for running batch jobs in…parallel
  • flock for making sure your cron job is only running one instance at any given time
  • the $() for getting the output from a command that was mentioned earlier is great, and you can also
  • I’m not sure where exactly it comes from, I think it ships with perl in deb-based distros, but the rename command is great for bulk-renaming jobs

Printing CRC checksum and byte count of a file

cksum foo.txt

File status output

stat foo.txt

Get the last modified date of a file

echo $(stat -c %y foo.bar)

Generating tar.gz files with current date/time name pattern

tar -czf $(date +%Y%m%d%H%M%S).tar.gz foo

Get the process list ordered by memory and cpu usage:

clear; ps -auxf | sort -nr -k 4 | head -10

Which :)

which name, for instance where is the dnf command on fedora… which dnf gives /usr/bin/dnf

Which :)

which name, for instance where is the dnf command on fedora… which dnf gives /usr/bin/dnf