Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- python -m SimpleHTTPServer
- Serve current directory tree at http://$HOSTNAME:8000/
- cd -
- change to the previous working directory
- mtr google.com
- mtr, better than traceroute and ping combined
- mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.
- As mtr starts, it investigates the network connection between the host mtr runs on and HOSTNAME. by sending packets with purposly low TTLs. It continues to send packets with low TTL, noting the response time of the intervening routers. This allows mtr to print the response percentage and response times of the internet route to HOSTNAME. A sudden increase in packetloss or response time is often an indication of a bad (or simply over?loaded) link.
- > file.txt
- Empty a file
- $ssh-copy-id user@host
- Copy ssh keys to user@host to enable password-less ssh logins.
- reset
- Salvage a borked terminal
- If you bork your terminal by sending binary data to STDOUT or similar, you can get your terminal back using this command rather than killing and restarting the session. Note that you often won't be able to see the characters as you type them.
- ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg
- Capture video of a linux desktop
- 'ALT+.' or '<ESC> .'
- Place the argument of the most recent command on the shell
- When typing out long arguments, such as:
- cp file.txt /var/www/wp-content/uploads/2009/03/
- You can put that argument on your command line by holding down the ALT key and pressing the period '.' or by pressing <ESC> then the period '.'. For example:
- cd 'ALT+.'
- would put '/var/www/wp-content/uploads/2009/03/ as my argument. Keeping pressing 'ALT+.' to cycle through arguments of your commands starting from most recent to oldest. This can save a ton of typing.
- mount | column -t
- currently mounted filesystems in nice layout
- Particularly useful if you're mounting different drives, using the following command will allow you to see all the filesystems currently mounted on your computer and their respective specs with the added benefit of nice formatting.
- ssh -N -L2001:localhost:80 somemachine
- start a tunnel from some machine's port 80 to your local post 2001
- now you can access the website by going to http://localhost:2001/
- echo "ls -l" | at midnight
- Execute a command at a given time
- This is an alternative to cron which allows a one-off task to be scheduled for a certain time.
- dig +short txt <keyword>.wp.dg.cx
- Functions: dig
- Query Wikipedia via console over DNS
- Query Wikipedia by issuing a DNS query for a TXT record. The TXT record will also include a short URL to the complete corresponding Wikipedia entry.You can also write a little shell script like:
- $ cat wikisole.sh
- #!/bin/sh
- dig +short txt ${1}.wp.dg.cx
- and run it like
- ./wikisole.sh unix
- were your first option ($1) will be used as search term.
- netstat -tlnp
- Lists all listening ports together with the PID of the associated process
- The PID will only be printed if you're holding a root equivalent ID.
- Comments (8) | Add to favourites | Report as malicious | Submit alternative | Report as a duplicate
- dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp
- output your microphone to a remote computer's speaker
- This will output the sound from your microphone port to the ssh target computer's speaker port. The sound quality is very bad, so you will hear a lot of hissing.
- curl -u user:pass -d status="Tweeting from the shell" http://twitter.com/statuses/update.xml
- Update twitter via curl
- !!:gs/foo/bar
- Runs previous command replacing foo by bar every time that foo appears
- Very useful for rerunning a long command changing some arguments globally.
- As opposed to ^foo^bar, which only replaces the first occurrence of foo, this one changes every occurrence.
- mount -t tmpfs tmpfs /mnt -o size=1024m
- Mount a temporary ram partition
- Makes a partition in ram which is useful if you need a temporary working space as read/write access is fast.
- Be aware that anything saved in this partition will be gone after your computer is turned off.
- man ascii
- Quick access to the ascii table.
- sshfs name@server:/path/to/folder /path/to/mount/point
- Mount folder/filesystem through SSH
- Install SSHFS from http://fuse.sourceforge.net/sshfs.html
- Will allow you to mount a folder security over a network.
- curl ifconfig.me
- Get your external IP address
- curl ifconfig.me/ip -> IP Adress
- curl ifconfig.me/host -> Remote Host
- curl ifconfig.me/ua ->User Agent
- curl ifconfig.me/port -> Port
- thonks to http://ifconfig.me/
- use iperf. It's a client server arrangement in that you run it in server mode at one end and connect to its from another computer on the other side of the network.
- One both machines run:
- sudo apt-get install iperf
- Then on Computer A:
- iperf -s
- And on Computer B:
- iperf -c <address of Computer A>
- On the client machine, you'll see something like this:
- oli@bert:~$ iperf -c tim
- ------------------------------------------------------------
- Client connecting to tim, TCP port 5001
- TCP window size: 16.0 KByte (default)
- ------------------------------------------------------------
- [ 3] local 192.168.0.4 port 37248 connected with 192.168.0.5 port 5001
- [ ID] Interval Transfer Bandwidth
- [ 3] 0.0-10.0 sec 1.04 GBytes 893 Mbits/sec
- Of course, if you're running a firewall on the server machine, you'll need to allow connections on port 5001 or change the port with the -p flag.
- * In bash, 'ctrl-r' searches your command history as you type
- SHELL - APPEND ONE FILE TO ANOTHER IN LINUX - STACK OVERFLOW
- cat file2 >> file1
- Using `find` is nice to get just directories:
- $ find . -type d -maxdepth 1
- Here's my list, a very compact plaintext file: http://mmb.pcb.ub.es/~carlesfe/unix/tricks.txt
- I have marked with a * those which I think are absolutely essential
- Items for each section are sorted by oldest to newest. Come back soon for more!
- BASH
- * In bash, 'ctrl-r' searches your command history as you type
- - Add "set -o vi" in your ~/.bashrc to make use the vi keybindings instead
- of the Emacs ones. Takes some time to get used to, but it's fantastic!
- - Input from the commandline as if it were a file by replacing
- 'command < file.in' with 'command <<< "some input text"'
- - '^' is a sed-like operator to replace chars from last command
- 'ls docs; ^docs^web^' is equal to 'ls web'. The second argument can be empty.
- * '!!:n' selects the nth argument of the last command
- 'ls file1 file2 file3; cat !!:1-2' shows all files and cats only 1 and 2
- - More in-line substitutions: http://tiny.cc/ecv0cw
- - 'nohup ./long_script &' to leave stuff in background even if you logout
- - 'cd -' change to the previous directory you were working on
- - 'ctrl-x ctrl-e' opens an editor to work with long or complex command lines
- * Use traps for cleaning up bash scripts on exit http://tiny.cc/traps
- VIM
- - ':set spell' activates vim spellchecker. Use ']s' and '[s' to move between
- mistakes, 'zg' adds to the dictionary, 'z=' suggests correctly spelled words
- TOOLS
- * 'htop' instead of 'top'
- - 'ranger' is a nice console file manager for vi fans
- - Use 'apt-file' to see which package provides that file you're missing
- - 'dict' is a commandline dictionary
- - Learn to use 'find' and 'locate' to look for files
- - 'find . -type d -exec chmod g+x {} \;' let people in your group access
- folders without messing up file permissions (never do 'chmod g+x * -R'!)
- - Compile your own version of 'screen' from the git sources. Most versions
- have a slow scrolling on a vertical split or even no vertical split at all
- * 'trash-cli' sends files to the trash instead of deleting them forever.
- Be very careful with 'rm' or maybe make a wrapper to avoid deleting '*' by
- accident (e.g. you want to type 'rm tmp*' but type 'rm tmp *')
- - 'file' gives information about a file, as image dimensions or text encoding
- - 'sort | uniq' to check for duplicate lines
- - 'echo start_backup.sh | at midnight' starts a command at the specified time
- - Pipe any command over 'column -t' to nicely align the columns
- * Google 'magic sysrq' and learn how to bring you machine back from the dead
- - 'diff --side-by-side fileA.txt fileB.txt | pager' to see a nice diff
- * 'j.py' http://tiny.cc/62qjow remembers your most used folders and is an
- incredible substitute to browse directories by name instead of 'cd'
- - 'dropbox_uploader.sh' http://tiny.cc/o2qjow is a fantastic solution to
- upload by commandline via Dropbox's API if you can't use the official client
- NETWORKING
- - SMB is better than NFS. Use 'sshfs_mount' as a last resort,
- any network failure will be trouble
- - 'python -m SimpleHTTPServer 8080' shares all the files in the current
- folder over HTTP, port 8080
- - 'ssh -R 12345:localhost:22 server.com "sleep 1000; exit"' forwards
- server.com's port 12345 to your local ssh port, even if you machine
- is not externally visible on the net.
- Now you can 'ssh localhost -p 12345' from server.com and you will
- log into your machine.
- 'sleep' avoids getting kicked out from server.com for inactivity
- * Read on 'ssh-keygen' to avoid typing passwords every time you ssh
- - 'socat TCP4-LISTEN:1234,fork TCP4:192.168.1.1:22' forwards your port
- 1234 to another machine's port 22. Very useful for quick NAT redirection.
- * Configure postfix to use your personal Gmail account as SMTP:
- http://tiny.cc/n5k0cw. Now you can send emails from the command line.
- 'echo "Hello, User!" | mail [email protected]'
- - Some tools to monitor network connections and bandwith:
- 'lsof -i' monitors network connections in real time
- 'iftop' shows bandwith usage per *connection*
- 'nethogs' shows the bandwith usage per *process*
- * Use this trick on .ssh/config to directly access 'host2' which is on a private
- network, and must be accessed by ssh-ing into 'host1' first
- Host host2
- ProxyCommand ssh -T host1 'nc %h %p'
- HostName host2
- -~-
- (CC) by-nc, Carles Fenollosa <[email protected]>
- Retrieved from http://mmb.pcb.ub.es/~carlesfe/unix/tricks.txt
- Last modified: Mon 07 Jan 2013 09:48:46 PM CET
Advertisement
Add Comment
Please, Sign In to add comment