Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands by starchox from sorted by
Terminal - Commands by starchox - 26 results
find ./ ! -name 'excludepattern' | xargs -i cp --parents {} destdir
2010-09-27 21:36:50
User: starchox
Functions: cp find xargs
Tags: find xargs cp
3

Preserve file structure when coping and exclude some file o dir patterns

find . -name 'pattern'| xargs du -hc
cat /proc/acpi/thermal_zone/*/temperature
2010-03-28 01:30:14
User: starchox
Functions: cat
0

A quick way of know the temperature info.

qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
2010-01-26 17:50:10
User: starchox
3

If you wish to launch the kde4 screen saver without the password prompt to exit, use this command:

qdbus org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SetActive True

Also can be done with:

/usr/lib/kde4/libexec/kscreenlocker --forcelock
dir='path to file'; tar cpf - "$dir" | pv -s $(du -sb "$dir" | awk '{print $1}') | tar xpf - -C /other/path
2010-01-19 19:05:45
User: starchox
Functions: awk dir du tar
Tags: copy tar cp
-2

This may seem like a long command, but it is great for making sure all file permissions are kept in tact. What it is doing is streaming the files in a sub-shell and then untarring them in the target directory. Please note that the -z command should not be used for local files and no perfomance increase will be visible as overhead processing (CPU) will be evident, and will slow down the copy.

You also may keep simple with, but you don't have the progress info:

cp -rpf /some/directory /other/path
file='path to file'; tar -cf - "$file" | pv -s $(du -sb "$file" | awk '{print $1}') | gzip -c | ssh -c blowfish user@host tar -zxf - -C /opt/games
2010-01-19 16:02:45
User: starchox
Functions: awk du file gzip ssh tar
3

You set the file/dirname transfer variable, in the end point you set the path destination, this command uses pipe view to show progress, compress the file outut and takes account to change the ssh cipher. Support dirnames with spaces.

Merged ideas and comments by http://www.commandlinefu.com/commands/view/4379/copy-working-directory-and-compress-it-on-the-fly-while-showing-progress and http://www.commandlinefu.com/commands/view/3177/move-a-lot-of-files-over-ssh

tune2fs -O extents,uninit_bg,dir_index /dev/yourpartition
2009-06-23 17:42:01
User: starchox
Functions: tune2fs
5

Before doing this, back-up all data on any ext3 partitions that are to be converted to ext4.

After running previous command you MUST run fsck, is needed to return the filesystem to a consistent state.

fsck -pDf /dev/yourpartition

Edit /etc/fstab and change the 'type' from ext3 to ext4 for any partitions that are converted to ext4.

ssh -L :: -L :: @
2009-06-22 19:12:48
User: starchox
Functions: ssh
10

Thankfully, the ssh command allows you to specify multiple tunnels through the same server in one command.

Remeber if you want a priviliged port on your machine, you must use root or sudo account.

convert image123.png -colors 14 -resize 640x480 grubimg.xpm
2009-03-12 22:55:10
User: starchox
Tags: Linux grub boot
3

* size must be 640?480 pixels

* only has 14 colors

* save it in XPM format

Edit /boot/grub/menu.lst and add

splashimage=(hd0,0)/boot/grub/grubimg.xpm

make sure for your path name and hard disk

find /usr/lib -maxdepth 1 -type l -print0 | xargs -r0 du -Lh
2009-03-07 00:17:45
User: starchox
Functions: du find xargs
3

You also can sum the file usage of all files

find /usr/lib -maxdepth 1 -type l -print0 | xargs -r0 du -Lch
ttmkfdir mkfontdir fc-cache /usr/share/fonts/miscttf
2009-03-06 21:28:17
User: starchox
Functions: fc-cache
5

First you have to create a directory in your system, where the fonts will be stored, and copy them.

sudo mkdir /usr/share/fonts/miscttf; sudo cp *.ttf /usr/share/fonts/miscttf

After recharge cache with the command

find . -type d \( -name DIR1 -o -name DIR2 \) -prune -o -type f -print0 | xargs -r0 md5sum
2009-03-05 21:26:24
User: starchox
Functions: find xargs
Tags: bash
4

Useful if you want get all the md5sum of files but you want exclude some directories. If your list of files is short you can make in one command as follow:

find . -type d \( -name DIR1 -o -name DIR2 \) -prune -o -type f -exec md5sum {} \;

Alternatively you can specify a different command to be executed on the resulting files.

tar zcpf backup.tgz --exclude=/proc --exclude=backup.tgz /
2009-02-18 19:31:27
User: starchox
Functions: tar
2

You can exclude more system folders or individual files which are not necessary for the backup and can be recreated after the restore procedure, like /lost+found, /mnt, /media, /tmp, /usr ...

Restoring the above backup procedure is as simple as becoming root and typing:

tar zxpf backup.tgz -C /

You can extract any file or directory out of the backup.tgz file for recovery, for instance, if you have a corrupt or mis-configured fstab file, you could simply issue the command:

tar zxpf backup.tgz /ect/fstab -C /

Other options:

v add verbose option to see files processed

A far safer solution is to restore the desired files under a different directory, and then compare, move, or update the files to their original locations afterward.

rm ./-filename
2009-02-18 18:36:25
User: starchox
Functions: rm
5

Using the redundant ./ directory information prevents the dash from occurring at the beginning of the filename, and being interpreted as an option of the rm command.

Also works using:

rm -- -filename
blockdev --setra 1024 /dev/sdb
2009-02-18 16:27:01
User: starchox
2

(WARN) This will absolutely not work on all systems, unless you're running large, high speed, hardware RAID arrays. For example, systems using Dell PERC 5/i SAS/SATA arrays. If you have a hardware RAID array, try it. It certainly wont hurt.

You may be can test the speed disk with some large file in your system, before and after using this:

time dd if=/tmp/disk.iso of=/dev/null bs=256k

To know the value of block device parameter known as readahead.

blockdev --getra /dev/sdb

And set the a value 1024, 2048, 4096, 8192, and maybe 16384... it really depends on the number of hard disks, their speed, your RAID controller, etc. (see sample)

ls -d */
2009-02-18 14:00:42
User: starchox
Functions: ls
8

This command would be useful when it is desirable to list only the directories.

Other options

Hidden directory

ls -d .*/

Other path

ls -d /path/to/top/directory/.*/

Long format:

ls -ld */
nmap -sS -P0 -sV -O <target>
2009-02-18 07:32:03
User: starchox
Tags: Network net
18

Where < target > may be a single IP, a hostname or a subnet

-sS TCP SYN scanning (also known as half-open, or stealth scanning)

-P0 option allows you to switch off ICMP pings.

-sV option enables version detection

-O flag attempt to identify the remote operating system

Other option:

-A option enables both OS fingerprinting and version detection

-v use -v twice for more verbosity.

nmap -sS -P0 -A -v < target >
CONVERT D: /FS:NTFS
2009-02-18 05:56:07
User: starchox
-1

You can convert a FAT or FAT32 volume to an NTFS volume without formatting the drive, though it is still a good idea to back up your data before you convert.

defaults write com.apple.dashboard mcx-disabled -boolean YES; killall Dock
2009-02-17 23:22:24
User: starchox
Functions: killall write
0

Dashboard is OS X utility application. When you hit F12, Dashboard springs forward, dimming the background, some people have claimed memory or performance problems. In my case, I just don't use it, there may be other reasons you?d rather not have Dashboard available.

Change YES to NO to restore the previous functionality.

wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com
2009-02-17 22:53:07
User: starchox
Functions: wget
151

-p parameter tells wget to include all files, including images.

-e robots=off you don't want wget to obey by the robots.txt file

-U mozilla as your browsers identity.

--random-wait to let wget chose a random number of seconds to wait, avoid get into black list.

Other Useful wget Parameters:

--limit-rate=20k limits the rate at which it downloads files.

-b continues wget after logging out.

-o $HOME/wget_log.txt logs the output

vncserver -nohttpd -name hidef-server -depth 24 -geometry 1440x900
2009-02-17 17:50:33
User: starchox
Tags: Network , net
3

-nohttpd don't run mini-httpd if VNC java applet is found

-name change the name of the desktop, it's passed to xstartup script via $VNCDESKTOP, run different set of apps acording the name.

-depth pixel depth in bits of the desktop, default is 16

-geometry size of the desktop, default is 1024x768

grep -c -e '^cpu[0-9]\+' /proc/stat
fortune -s -c -a | cowthink -d -W 45
2009-02-16 21:45:33
User: starchox
-4

The popular fortune program telling by a cow (see sample).

- fortune

- cowsay

perl -pi -e 's:^V^M::g' <filenames>
2009-02-16 21:17:40
User: starchox
Functions: perl
1

That "^M" is Ctrl-M, which is a carriage return, and is not needed in Unix file systems.

Where ^V is actually Ctrl-V and ^M is actually Ctrl-M (you must type these yourself, don't just copy and paste this command). ^V will not be displayed on your screen.

netstat -putona
2009-02-16 19:14:35
User: starchox
Functions: netstat
6

-p PID and name of the program

-u on a UDP port.

-t also TCP ports

-o networking timer

-n numeric IP addresses (don't resolve them)

-a all sockets