Commands by pibarnas (3)

  • Using "", which allow bash commands to be interpreted by sed scripts, I've embedded a sed script in another sed substitution, in case, the 4th line of the file at the end of the second one. Show Sample Output


    0
    $ sed "2s/$/ $(sed -n '4p' sound.desktop)/" sound.desktop
    pibarnas · 2016-08-23 02:50:31 0
  • N: On the current line, sed will display it on pattern space, plus a \n (new line); but s/\n//: Will get rid of new line displayed on pattern space, joining the current line's end with the start of the next line Useful in scripts. Show Sample Output


    2
    sed 'X{N;s/\n//;}' file.txt (where X is the current line)
    pibarnas · 2016-07-30 14:27:20 0
  • Using a for loop, rename all files with .MP3 extension to .mp3. Show Sample Output


    0
    find . -type f -name *.MP3 -print0 | xargs -0 -i rename .MP3 .mp3 {}
    pibarnas · 2012-04-29 02:44:44 2

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands


Check These Out

Get current logged in users shortname

Watch YouTube and other Flash videos via mplayer (or whatever)
Many sites with Flash video players will download video files to /tmp on Linux, with temporary filenames like "FlashbGTHm4". These will often play in mplayer, totem, or other movie playing software. You must first navigate to a video page, let it start loading, and then pause playback.

Encode a string using ROT47
This command will encode a string using the ROT47 cipher.

Mirror a directory structure from websites with an Apache-generated file indexes
wget/curl/friends are not good with mirroring files off websites, especially those with Apache-generated directory listings. These tools endlessly waste time downloading useless index HTML pages. lftp's mirror command does a better job without the mess.

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Shows all packages installed that are recommended by other packages
Shows the packages installed on your system that are recomemnded by other packages. You should remove these packages.

ignore hidden directory in bash completion (e.g. .svn)
add it in ~/.bashrc install bash-completion

Create .pdf from .doc
sudo apt-get install cups-pdf

Vi - Matching Braces, Brackets, or Parentheses
This is a simple command for jumping to the matching brace, square bracket, or parentheses. For example, it can take you from the beginning of a function to the end with one key stroke. To delete everything between the pairs of {}, [], or (), issue the command: $ d% To replace text between pairs of braces, brackets, or parentheses, issue the command: $ c% You can also use this command to find out if an opening brace has been properly closed.

Tell local Debian machine to install packages used by remote Debian machine
(also works on Ubuntu) Copies the 'install,' 'hold,' 'deinstall' and 'purge' states of packages on the remote machine to be matched on the local machine. Note: if packages were installed on the local machine that were never installed on the remote machine, they will not be deinstalled by this operation.


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: