Commands tagged stdout (10)

  • 58
    strace -ff -e trace=write -e write=1,2 -p SOME_PID
    oernii2 · 2010-04-20 08:55:54 2
  • similar to the previous command, but with more friendly output (tested on linux)

    strace -ff -e write=1,2 -s 1024 -p PID 2>&1 | grep "^ |" | cut -c11-60 | sed -e 's/ //g' | xxd -r -p
    systemj · 2010-04-23 16:22:17 0
  • You have a script where =ALL= STDERR should be redirected to STDIN and you don't want to add "2>&1" at the end of each command... E.G.: ls -al /foo/bar 2>&1 Than just add this piece of code at the beginning of your script! I hope this can help someone. :)

    exec 2>&1
    morgents · 2010-08-05 08:24:18 0
  • Useful to recover a output(stdout and stderr) "disown"ed or "nohup"ep process of other instance of ssh. With the others options the stdout / stderr is intercepted, but only the first n chars. This way we can recover ALL text of stdout or stderr Show Sample Output

    strace -e write=1,2 -p $PID 2>&1 | sed -un "/^ |/p" | sed -ue "s/^.\{9\}\(.\{50\}\).\+/\1/g" -e 's/ //g' | xxd -r -p
    glaudiston · 2010-10-06 19:37:39 1
  • I've had a horrible time trying to pipe the output of some shell built-ins like 'time' to other programs. The built-in doesn't output to stdout or stderr most of the time but using the above will let you pipe the output to something else. Show Sample Output

    TIME=$( { time YOUR_COMMAND_HERE; } 2>&1 ) ; echo $TIME
    allrightname · 2010-11-18 15:48:05 0
  • save as shell script and pipe your command output Show Sample Output

    #!/bin/zsh SHL='\\e[0;31m' EHL='\\e[0m' while read line; do TEXT=$line for SSTR in $*; do TEXT=$(echo $TEXT | sed -e "s:$SSTR:${SHL}${SSTR}${EHL}:g") done echo -e $TEXT done
    steigr · 2012-06-06 12:57:50 0
  • This will be very helpful when you are debugging shell scripts, where you don?t want to display the echo statement and interested in only looking at the error messages. Similarly use 2> to supress error messages Show Sample Output

    cat file.txt > /dev/null
    ankush108 · 2012-06-26 18:34:12 0
  • Very convenient to for sending data to the clipboard for processing. However, note that tee will affect the buffering of the output (stdout won't be update very live). Show Sample Output

    alias t="tee >(pbcopy)"
    lgarron · 2014-01-24 12:41:07 0
  • Run a job in the background and prefix it's output with some string. This is particularly useful if you are running inside a docker container in a startup script (sue me, I'll run two jobs in a docker container if I want to) and you can run something like: /usr/sbin/nginx 2>&1 | awk '{print "[NGINX] " $0}' & /opt/jws-3.1/tomcat8/bin/ run 2>&1 | awk '{print "[TOMCAT] " $0}' & while true; do ; done it can also be combined with tee to create a file log as well as a stdout log, for example if the script above where a script called "/bin/" then you could run /bin/ | tee /var/log/containerlogs Show Sample Output

    nginx 2>&1 | awk '{print "[NGINX] " $0}' &
    hvindin · 2017-04-25 22:18:38 0
  • Adds the stdout (standard output) to the beginning of logfile.txt. Change "command" to whatever command you like, such as 'ls' or 'date', etc. It does this by adding the output to a temporary file, then adding the previous contents of logfile.txt to the temp file, then copying the new contents back to the logfile.txt and removing the temp file.

    command > tmp && cat logfile.txt >> tmp && tmp > logfile.txt && rm tmp
    akoumjian · 2009-04-05 22:00:32 7

What's this? 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

Calculate N!

Automatically skip bad songs in your MPD playlist.
Case insensitive. Also you can pull in the songs from a blacklist, one per line - while :; do (mpc current | grep -i -f blacklist.txt && mpc next); sleep 5; done

Show some trivia related to the current date
Contrary to logic, typing calendar won't show a calendar, that's the job of cal. Typing calendar will show some trivia related to the current date. Tested against many Linux distros and FreeBSD.

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

List all files modified by a command
This lists all files modified after calling some command using a temporal anchor.

tar the current directory wihtout the absolute path
tars the current directory (and its children) in an archive of the same name (plus ".tar" :)) in the parent directory without the absolute path, so that when the archive is extracted, only the current directory name is created for the path. Assumes bash/zsh.

Write comments to your history.
A null operation with the name 'comment', allowing comments to be written to HISTFILE. Prepending '#' to a command will *not* write the command to the history file, although it will be available for the current session, thus '#' is not useful for keeping track of comments past the current session.

combine `mkdir foo && cd foo` into a single function `mcd foo`
I find that I create a directory and then cd into that directory quite often. I found this little function on the internets somewhere and thought I'd share it. Just copy-paste it into you ~/.bash_profile and then `source ~/.bash_profile`.

Testing php configuration

Get your commandlinefu points (upvotes - downvotes)
This will calculate the your commandlinefu votes (upvotes - downvotes). Hopefully this will boost my commandlinefu points.

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.


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: