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/
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.
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:
See "Parameter Expansion" in the bash manpage. They refer to this as "Use Alternate Value", but we're including the var in the at alternative.
The read command reads input and puts it into a variable. With -i you set an initial value. In this case I used a known environment variable.
In this case the current user has proxy variable set which allows access to the rpm on the internet but needs root privs to install it.
Running sudo -E preserves the current user proxy var and allows the rpm install to be executed with sudo.
If this matches any files on your web server expect to find allot of malware spread throughout your server folders. Seems to target wordpress sites. Be sure to check your themes/theme-name/header.php files manually for various redirect scripting usually in the line right above the close head tag.
Good luck!
Someone quoted Pooh in an init script. Let's see it!
(Probably only works on Debian & friends)
You can search for CVEs at https://security-tracker.debian.org/tracker/ or use --report to get full links. This can be added to cron, but unless you're going to do manual patches, you'd just be torturing yourself.
This command will display the file, but you can change 'cat' to anything else
(type 'n' when prompted to cancel the command or anything else to proceed).
.
Some hints for newbies:
type
unset bar
to make 'bar' function annihilated.
For permanent usage you can put this (bar) function in your .bashrc (for bash) or in .profile (for sh).
With:
. ~/.bashrc
you can get all new inserted functions in .bashrc (so the function 'bar'
or whatever name you choose) immediately available.
tcpdump into file with date format for wireshark
capture trafic for wireshark from spesific eth interface
This command validates if exist any character different in 0-255 and dot.
If any characters different is typed the error menssage is showing.
Print out your age in days in binary.
Today's my binary birthday, I'm 2^14 days old :-)
.
This command does bash arithmatic $(( )) on two dates:
Today: $(date +%s)
Date of birth: $(date +%s -d YYYY-MM-DD)
The dates are expressed as the number of seconds since the Unix epoch (Jan 1970),
so we devide the difference by 86400 (seconds per day).
.
Finally we pipe "obase=2; DAYS-OLD" into bc to convert to binary.
(obase == output base)
Often you run a command, but afterwards you're not quite sure what it did.
By adding this prefix/suffix around [COMMAND], you can list any files that were modified.
.
Take a nanosecond timestamp: YYYY-MM-DD HH:MM:SS.NNNNNNNNN
date "+%F %T.%N"
.
Find any files that have been modified since that timestamp:
find . -newermt "$D"
.
This command currently only searches below the current directory.
If you want to look elsewhere change the find parameter, e.g.
find /var/log . -newermt "$D"
This lists all files modified after calling some command using a temporal anchor.
In pre-systemd systems, something like: "# grep sshd /var/log/messages" would display log events in /var/log/messages containing "sshd".
# journalctl -u sshd --no-pager
The above command displays similar results for systemd systems.
(Note that this needs to be run with root permissions to access the log data.)
Extract only a specific file from a zipped archive to a given directory
unzip -j "myarchive.zip" "in/archive/file.txt" -d "/path/to/unzip/to"
./script.sh
# suspend process
{ctrl-Z}
# background process
bg
# list all backgrounded jobs
jobs
# bring it back to foreground
fg
A wrapper around ssh to automatically provide logging and session handling.
This function runs ssh, which runs screen, which runs script.
.
The logs and the screen session are stored on the server.
This means you can leave a session running and re-attach to it later, or from another machine.
.
.
Requirements:
* Log sessions on a remote server
* Transparent - nothing extra to type
* No installation - nothing to copy to the server beforehand
.
Features:
* Function wrapper delegating to ssh
- so nothing to remember
- uses .ssh/config as expected
- passes your command line option to ssh
* Self-contained: no scripts to install on the server
* Uses screen(1), so is:
- detachable
- re-attachable
- shareable
* Records session using script(1)
* Configurable log file location, which may contain variables or whitespace
L="$HOME" # local variable
L="\$HOME" # server variable
L="some space"
.
Limitations:
* Log dir/file may not contain '~' (which would require eval on the server)
.
.
The sessions are named by the local user connecting to the server.
Therefore if you detach and re-run the same command you will reconnect to your original session.
If you want to connect/share another's session simply run:
USER=bob ssh root@server
.
The command above is stripped down to an absolute minimum.
A fully expanded and annotated version is available as a Gist (git pastebin):
https://gist.github.com/flatcap/3c42326abeb1197ee714
.
If you want to add timing info to script, change the command to:
ssh(){ L="\$HOME/logs/$(date +%F_%H:%M)-$USER";/usr/bin/ssh -t "$@" "mkdir -p \"${L%/*}\";screen -xRRS $USER script --timing=\"$L-timing\" -f \"$L\"";}
Downloads Bluetack's level 1 IP blocklist in .p2p format, suitable for various Bittorrent clients.