(Useful) Stupid Unix Tricks?
So the other day I messaged another admin from the console using the regular old 'write' command (as I've been doing for over 10 years). To my surprise he didn't know how to respond back to me (he had to call me on the phone) and had never even known you could do that. That got me thinking that there's probably lots of things like that, and likely things I've never heard of. What sorts of things do you take for granted as a natural part of Unix that other people are surprised at?
I find a combination of find/grep to be pretty useful. Not sure about how unknown it is, but I do know that several UI-based linux admins around our office don't know about "stacking" commands. (I know, I know, one would think they would be mutually-exclusive
find . | grep [string]
Hi, I Boris. Hear fix bear, yes?
I'm sure everyone at some point is surprised of tabbed completion.
I discovered if you give the echo shell command an asterisk as a parameter, it dumps out the file names of the current directory. (The sad thing is I had a practical use for this when a less-than-clueful-collegue deleted the /bin directory, leaving the system without an ls program).
--
Luck is just skill you didn't know you had.
Works like a charm for finding a file containing a keyword. Another one I often use is:
Human readable disk space:
Track down where your space is going:
Javascript + Nintendo DSi = DSiCade
I've seen Windows people go slack-jawed in astonishment as I ssh to the other side of the world and run X programs over forwarding.
Some refuse to believe it, others shake their heads and walk away.
more like
sudo rm -rf /
On the older systems, talk was a great utility.
dd, device duplicator / disk destroyer
mount, what I can't have a desktop icon?
also managing disk volumes and the old conventions of /opt, /u, /usr, /usr/local
This new fangled Linux craze with all of the UI tools is feeding it. Redhat is training admins that are dependent on a given release of their enterprise software (which I am a huge fan of) but not teaching them how it works under the hood.
How about slirp? scp?
The one ray of hope seems to be a new generation hacking their bsd and linux based (iPhone/Android) phones and having fun in a somewhat embedded (but full blown) *nix environment.
In terms of navigation directories efficiently, I find that "cd -" is often forgotten (changes directory to your previous directory). I personally find it very useful, and couldn't live without it!
Before IRC and IM there were finger and talk. They don't work as often as they used to because admins generally don't open them up to the public. But, you used to be able to see if someone was online using finger and then chat with them using talk.
finger user@example.com
talk user@example.com
You can usually still use these with another user on the same host as the author did with write.
fg, bg, kill, Ctrl-Z, &. Learn it. Know it. Live it.
Even if they do know about job control, I've seen people look for a background job with ps, and then kill it using the PID. In most shells you can just do kill %, e.g. kill %1
Hands in my pocket
Synaptic Package Manager is a GUI thing that comes with Ubuntu and has a search function. You just put a checkbox next to the packages you would like to install and press "apply".
meh
You're not giving echo an asterisk as a paratemer. You're giving the shell an asterisk, which it dutifully expands. echo (which in this case is a shell builtin, but it doesn't have to be then just echoes them back.
This isn't some echo peculiarity. It works for anything, even commands that don't normally take files, or even with files that look like switches (conversely, if you want to treat all subsequent arguments as files, not switches, most programs have a '--' switch):
$ ls
a -l b c
$ ls *
-rw-r--r-- 1 marcansoft users 0 2008-11-05 21:58 a
-rw-r--r-- 1 marcansoft users 0 2008-11-05 21:58 b
-rw-r--r-- 1 marcansoft users 0 2008-11-05 21:58 c
$ ls -- *
a -l b c
In the second example, ls sees "ls a -l b c" and takes -l as a switch instead of a filename.
Quite a handy way to switch between several applications on a single terminal: Ctrl+Z stops the current program, then bg to resume it and send to background, fg to resume in foreground. You can have several stopped programs and pick one with fg 3, for example. See all stopped jobs with jobs.
Few things to note, wget still prints to STDOUT, even when backgrounded, so I run it in screen. Also, pico may require a -z switch to allow suspension.
One great feature of find that many people are unaware of is that you can use -exec as a test, not just as an action. For example, this is equivalent to your command above:
find . -exec grep -q {} \; -print
The "-print" action is only executed if the -exec command returns success.
You can do a lot of handy things with this. Here's a real-world example from earlier today. I wanted to change the mime-type of all the xml files in my svn repository from "application/xml" to "text/xml":
find . -name \*.xml -exec sh -c "svn propget svn:mime-type {} | grep -q application/xml" \; -exec svn propset svn:mime-type text/xml {} \;
Some more common ones I've thought of:
screen - too useful, run apps in a virtual console which you can attach, deattach and share
cd `pwd -P` - Jump into the real directory (from a linked directory).
history - use it with grep if you forgot what you did
strings - just show the printable strings from a file
tail and head - tail -f is a lifesaver
sftp - i really shouldn't need to explain this.
file - do magic stuff
Hope that's some help.
This is an important difference between unix shells and dos/windows shell. In Unix, the wildcards like "*" are handled by the shell and expanded before the program ever sees the arguments. In DOS/Windows, the expansion must be done by the program itself. This is why every program in unix understand wildcards, while only some do in the MS world.
Why not just use sed if you are on the command line?
...etc.
sed "s/searchme/replaceme/g" *
MCSE? No, sir...I don't do Windows. Yes, I am an idealist. What's your point?
Assuming you already know the simple stuff like how to use shell quotes correctly, what you can do with ps and top, ...
Need to know the serial number of a server or bios version or many other things dmidecode is your friend.
When I pop up with my laptop to discuss with a colleague, after a while I might do on their computer:
xhost +mylaptopname
and on my laptop I do:
x2x thecomputername:0 -west
Then suddenly my mouse can go over the two computers, my keyboard works on both as well, and I can even copy-paste between the two computers. It looks like the two computers got united. In a flash, newbies get a new idea of what means unix and X ;-)
The advantage of the directory stack over "cd -" is that the directory stack always remembers where you last were. "cd -" only remembers until you change directories again.
In tcsh (I don't know other shells), you can do directory stack substitution. =0 is current directory, =1 is one up, =2 is two up, and so on.
I also use bindkeys to bind Control-G to 'dirs -v' so I can look at the directory stack with ease, even in the middle of a command.
Personally, I think directory stack commands are the least-known, but most useful feature in tcsh.
The ultimate goal of science is to unify all forces of nature to a single law that can be silk-screened onto a T-shirt.
!! in bash uses the last command you entered. $ make_me_a_sandwich What? No. $ sudo !! okay. $
To find a string in a file I used to do "find . | xargs grep foo"
It's generally wise to use -print0 and -0...
Finally! A year of moderation! Ready for 2019?
Actually, you don't need fingerd running if you looking at the local machine. IIRC it reads the local wtmp or wtmpx file to get the information.
ls -l | sort -n +4 -- sorts files in size order, good for finding big files in a directory
du -s * | sort -n -- similar to above, find the biggest files & subdirectories of the current dir
du | xdu -- only when you're in X, obviously. Better grain than above, with the ability to drill down into subdirectories
Reverse a bash-Array:
j=0; for i in ${array[*]}; do newind="$(( ${#array[*]} - ($j+1)))"; echo j=$j newind=$newind; newarr[$newind]=$i; let j++; done
This shows all attached block devices (it also errors like crazy, hence the | more)
blockdev --report /dev/* | more
Redirect stderr much?
Oh, say does that Star-Spangled Banner entwine / The myrtle of Venus with Bacchus's vine?
Embedding output... use the backtick, not the doubletick. '`' not '"'
echo There are `ls | wc -l` entries in this directory.
In ksh, you can also use the syntax $(command string)
echo There are $(ls | wc -l) entries in this directory.
Mark J. Cecil -- Senior UNIX Engineer
New Orleans, Louisiana
http://notrealswift.blogspot.com
Well, to be fair it's a relatively new feature in bash, so perhaps ubuntu is just the first place you've tried that makes bash completion the default. Here's a blog posting on changing completion to make it smarter, so perhaps you can follow some links and learn how to make the shell do what you want. That's sort of the point...
Instead of using find and xargs it's sometimes easier to use the -exec parameter to find:
find . -type f -exec ls -l {} \;
xargs is very useful in other circumstances. One thing that I get asked about a lot is how to pass variables. Main thing to remember is to call the shell via xargs to process variables and other parameters.
BTW: How does one ork a cow?
DISCLAIMER: Don't run this!
I didn't think I needed to say this, but I just showed someone this and they thought it was a legitemately helpful command...
Add this to your .inpurc file:
Then you can do it either way. <Ctl-Space> works like Windows, tab works like bash. Also add these if you want a little additional sanity:
cd -
Change to your previous directory. It's great for going from dev to test environments from time to time.
ls -l 'locate gcc' // Output would give you a long listing of wherever gcc is located
Maybe it is just my font, but I think those should be backticks. Variables and commands cannot interpolate strings with single quotes ''.
Backticks, however, will allow command output redirection.
ls -l `locate gcc`
You could write it this way, but you threw in double-quotes and do not really need them here.
find ~/tvshows -name doctor\*who\* -exec mplayer -fs "{}" ";"
You could type the following, with the same effect. The find command with the -exec switch, is forking off a sub-shell for every argument passed by the find command, the \; or ";" is a command terminator for the sub-shell which is forked off. Depending on the task this could run very, very, very slow. For heavy-duty tasks there is a pretty neat utility shipped with every distribution of Perl, check out find2perl sometime.
find ~/tvshows -name "doctor*who*" -exec mplayer -fs {} \;
To generate pure Perl code to do the same loop, run the following. If you tack on a '| perl', after the find2perl command, it will pipe the generated code straight to the language interpreter and execute.
find2perl ~/tvshows -name "doctor*who*" -exec mplayer -fs {} \;
/^([Ss]ame [Bb]at (time, |channel.)){2}$/
My previous place of employment was a Mac shop, where I discovered the wonderful pbcopy and pbpaste commands. Why they aren't a standard part of every X windows distribution, I'll never know, but they are damned handy.
What they do is allow you to read and write from the cut-and-paste buffer from the command line. "pbpaste" will print the currently copied text to stdout, while "pbcopy" will replace the buffer with stdin.
Fortunately, there are some third-party X equivalents for this, such as xsel or xclip, which can be adapted to work in the same way.
Rougly equivalent:
pbcopy
xsel -i --clipboard
xclip -in -selection clipboard
pbpaste
xsel -o --clipboard
xclip -o -selection clipboard
grep --color
For some reason, many people are greatly surprised when they figure out that grep will highlight matches for them.
The find command is definitely a good tool to be familiar with. Also, I've done a lot of really wacky stuff with sed in the past. (and sed experience can help you to work with ed and even ex, for those times the system has crashed so hard that's all you've got) (though I don't think I've had that happen since I left Ultrix).
dc and bc are good things at times. Really, I do a whole lot of really complicated manipulation of data with the various utilities, sometimes all in one long pipeline and sometimes in multiple complicated stages. An example of that is where I'll often take a du output, use sed to convert G, K, and M to the proper amount of zeroes (or maybe there's a du option to do that automatically, I forget), awk out the 1st column and print each as "$1 +" with no returns, echo a "0" at the end, and pipe the whole thing through bc, to get a "grand total." (maybe that's a bad example, but the ([do something]; echo 0) | bc is definitely something I've done a lot over the years.
I used to have aliases to call dc to do radix conversion (like echo "2 o 1337 p" | dc to get "10100111001"). (there's also a great .sig line out there that does some kind of crazy dc stack program to print out an ascii message, that I wasted a good chunk of time figuring out on paper to understand how it worked).
Another great trick I've been using for 20 years is dd piped through ssh, to copy a local hard drive image over the net to another machine, or vice-versa (well, okay, 20 years ago it was rsh). (like boot off a live CD, "(ssh remote cat /my/image.dd) | dd of=/my/dev" to rebuild a local drive from a remote backup.
There are lots of other things, way too many to write here. I'm sure there's a website out there somewhere.
Oh, and another great one from the days when I'd get files with untypable characters in the filename -- "ls -i" to get a files inode, then "find . -inum [inode] -exec rm {} \;" to delete that (or mv {} newname to rename it). Not sure I need that much any longer, but at the time it was VERY useful.
lsof is a LIFE SAVER for trying to find what's still using something in a mounted resource when trying to unmount something. For example:
/mnt/myMount
/mnt/myMount open
/dev/snd
lsof
That will list which processes have anything under
It's also useful to find who's accessing what device. For example, say you're trying to listen to an mp3 and Amarok bitches about the sound device not being available. In that case, you could do something like this (assuming you're using ALSA):
lsof
That will list what processes are accessing any of your ALSA sound devices.
When I want to copy entire directory trees to a remote system while preserving all file attributes:
tar -czf - some_dir | ssh user@remote.host 'tar -C target_location -xzf -'
This also works when you want to copy something to a system that doesn't support scp (embedded devices)
ctrl+r (in bash?): reverse incremental search through history.
pushd/popd , change directory saving the old one on a stack.
sftp - i really shouldn't need to explain this.
I much prefer sshfs. Diff doesn't work so well over ftp ;)
tail and head - tail -f is a lifesaver
I use tail -F, which is the same as tail -f, but works on non-existent files. Useful when tailing log files from programs that start a new log file every time it runs. Using tail -F in this case, you can just leave tail running while you start and restart the program overwriting the log file.
I believe you mean NO CARRIER
There are a whole bunch of "history" tricks, to recall old commands without using the mouse.
When I started college, I studied the shell's man page until I knew them all. Some are so obscure I have forgotten them.
Generally, these involve an '!' character in some way.
Here are a few I use:
!! # run again the last command that was run
!9 # run again the command with history number 9
!v # run again the last command that started with a 'v'
!vi # run the last command that started with "vi"
!?foo? # run the last command that had the string "foo" anywhere in it
diff oldfile newfile
mv !$ !^ # same as "mv newfile oldfile"
# !$ is last arg of previous command, !^ is first arg
ls foo bar baz
rm -f !!* # same as "rm -f foo bar baz"
# !!* repeats all arguments from previous command
There are actually some baroque tricks that recall a previous command and perform a search-and-replace on it, but for anything that complicated I just recall the line and edit it. The baroque tricks would have been pretty darn cool back in the paper teletype days, though.
By the way, the Bash shell can be configured to edit command lines using vi or Emacs commands. I described how to do it in an article I wrote for Linux Journal magazine. It's the last section, "vi or Emacs Mode in the Shell".
http://www.linuxjournal.com/article/8361
Oh, not exactly a history trick, but here's something I use all the time: /tmp/files /tmp/files # edit list to include just the files I want /tmp/files`
ls -1 >
vi
rm `cat
# `cmd` inserts the standard output from cmd into the command line as if you typed it
ls -1 > /tmp/files /tmp/files :%s+.*+mv & /some/directory/path/&+ /tmp/files
vi
# edit list to include just the files I want
# now run this command:
# save file and quit vi
source
This moves the chosen files to "/some/directory/path". The breakdown of the vi command is as so:
: # invoke "ex mode" for search and replace command
% # run the following command on every line of the file
s # do a search and replace
+ # use a '+' for the command delimiter, so I won't have to backslash escape '/' chars in the path
.* # all characters on the line /some/directory/path/& # replace "foo" with "mv foo /some/directory/path/foo"
+ # end the match pattern, begin replace pattern
# & refers to the match pattern, thus all chars on the line
mv &
Takes less time to do it than to explain it!
The above is perhaps overkill if all the files are going to the same place. It's great if you want to send some files one place, some to another, because you can just edit the destinations until it looks right.
steveha
lf(1): it's like ls(1) but sorts filenames by extension, tersely
you don't have to use Ctrl-a. You can bind screen's escape to any key.
Climate Progress - Hell and High Water
Try: /dev/* 2> /dev/null
blockdev --report
as HTH NE1 (675604) said above.
blktool is probably good, but blockdev is on most Linux recovery CD's as default.
(otherwise it will get killed the moment you log out)
dd if=/dev/zero of=/dev/sdx bs=512 count=1
should clear out the MBR.
cd
takes you to your home directory.
Your head a splode
You only need a tiny bit of entropy to seed the pseudorandom number generator in /dev/urandom. Once it's seeded you get all the pseudorandom numbers you want. /dev/random gives you truly random numbers, and is highly dependent on the amount of entropy the system has. It will block if you run out of entropy, urandom will not.
Give me Classic Slashdot or give me death!
Along that line are pushd and popd. pushd <dir> changes to the specified directory and pushes it onto a stack of directories; popd changes to the directory at the top of the stack and removes it. There are commands for manipulating the directory stack but I don't know or use them.
With zsh, and I think with Bash as well, you can setopt AUTO_PUSHD and setopt PUSHD_SILENT and then cd behaves like pushd.
(Both of these commands, along with cd -, work in the Windows command interpreter too.)
I'd say most people don't know how to use SSH very well...
Stop typing passwords for every system: ssh-keygen, ssh-auth and ssh-add.
Transferring files both with scp/sftp and ssh user@host "cat file" > file, and the like.
Changing encryption algo for significantly improved speed, eg. -c arcfour
Enabling/disabling compression for internet/intranet. -C
An $HOME/.ssh/config file to map names to IP addresses, specify the default user names for each host, toggle compression per host, enable/disable port forwarding, keepalive, etc.:
host webserver
ForwardX11 no
ForwardAgent yes
Compression yes
hostname slashdot.org
port 2100
user cmdrtaco
And parenthesis and backticks seem to be going out of fashion in short order... Too bad, since they're quite time-saving: mkdir `date +%Y`
Slashdot gets worse every day... Pipedot: News for nerds, without the corporate slant
sshfs is truly pimp, but both deserve mention; AFAIK sshfs can't be used on a system where you don't have root that doesn't have FUSE installed.
For example, I did these to some of my favorite people:
banner "PORN HERE" > /dev/pts/4
echo "All files deleted." > /dev/pts/3
cat dictionary.list > /dev/pts2
--Chag
I can't live without svn. Svn is a revision control repository, usually used for source code. What makes it really powerful is that you can _easily_ have a history of everything that has changed in a file and when. On my systems, I keep /etc in svn, plus bind's zone files, plus all the non-image web content, and the "Network Documentation" folder.
Second trick, rsync. I use it to backup my home directory to another box. Very nice when you go through a hard drive/year.
Screen -x was my next pick, but somebody already mentioned it.
"echo ProtocolKeepAlives 120 >> /.ssh/config" No more dropped ssh sessions because of stupid nat boxes.
su -u Username -s .. become Username, but keep the current shell. Good for diagnosing permissions problems when the user has a /bin/false shell. (named/www-user/backup/etc).
A little awk goes a long way. Not the big-bad-I-am-a-programming-language-awk, but the smaller-friendlier extract one or two columns of text from something awk. ex. awk '{print $2}' prints the thing in the second column. Add -F the field separator tool and it gets really useful.
Better example. Here is a postfix log line.
Nov 5 16:27:19 pdc postfix/smtpd[13601]: 92B3F499C25F: client=exprod5mx254.postini.com[64.18.0.49]
Here is the awk to extract just the message id. awk -F': ' '{print $2}'
And here is the "I didn't get this message your mailserver must have eaten it" disprover. It searches the maillog for every message from or to a given address and extracts the full email transaction for that message id.
grep -i user@domain.com /var/log/maillog | grep smtpd | awk -F': ' '{print $2}' | sort -un > temp.fil && grep maillog -f temp.fil
Next trick, back ticks. `` Back ticks substitute the output of a command within a command.
Ex. Name a file after the date. echo "hi" > `date +%Y%M%d`.txt
On the subject of dates. date -d'yesterday' or 'last week' or '-4 hours' can be handy.
Last one. Loopback nat with Iptables, so you can access local hosts by their external ip. (Instead of setting up split dns.)
iptables -I POSTROUTING -s $local_network -d $local_network -j SNAT --to $lan_interface
My local network is 192.168.0.0/24 and the netfilter lan ip is 192.168.0.1, so that becomes...
iptables -t nat -A POSTROUTING -d 192.168.0.0/24 -s 192.168.0.0/24 -j SNAT --to 192.168.0.1
-ellie
I actually like less better than tail -f. If you less a file, and then hit SHIFT-F it will tail the file, but you can break out of it and scroll around and search for terms. Very handy while looking at log files.
Don't count your messages before they ACK.
LOL, that's awesome.
Curiosity was framed, Ignorance killed the cat.
The fd0 comes from the BIOS and not the O/S
If you tell the BIOS there is a fd0, it will simply report its existence to the O/S.
The O/S will simply assume there is no disk in there.
"I was in love with a beautiful blonde once, dear. She drove me to drink. It's the one thing I am indebted to her for."
Even better: use NX (http://www.nomachine.com/ - includes a "free edition"). Basically heavily compressed X forwarding, but also includes niceties such as being able to disconnect and reconnect sessions without killing the X clients. I use it over a VPN on the rare occasions I work from home, on a standard ADSL connection. Typing on an NX forwarded xterm is almost as quick as when SSH-ing in directly (which may seem a somewhat pointless use-case, but is the closest I know how to get to the behaviour of "standard" SSH with X forwarding). I also find I get *much* better responsiveness if I run VMWare Server Client on my work box, forwarded over NX, instead of running the client at home and connecting to the work VMWare server from there.*
Also available as FreeNX (http://freenx.berlios.de), but harder to set up IME.
* Which may just be another way of saying "VMWare's protocol sucks", but regardless, turns it from near unusable to very useful.
I do the same, luckily a lot of music players support something like
# audacious --play
# rhythmbox-client --play
for controlling the running app from the shell. The second actually goes over DBUS.
more often I use the opposite, --pause, or
# sleep 15m && sudo poweroff
for listening to some music in bed before falling asleep.
NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
And the VMS HELP pages were (and probably still are) inestimably better than Unix style man pages. Even 20 years later I still miss them.
or if you're a vi freak like me:
set -o vi
escape (enters command mode)
k to scroll up
/ to search
William of Ockham had no beard. The most likely explanation is that it was chewed off by squirrels every morning.
cal 9 1752
We must repeat.
Organizing them all is left as an exercise for the reader.
Cakewalk. Put the following in ~/.bash_profile or ~/.profile
For ubuntu:
SHELLID=(echo `tty` | sed 's!/!.!g')
HISTFILE=$HISTFILE$SHELLID
Logout. Log back in. Bada-bing.
If you're using bash, try adding
# don't overwrite history from several sessions
shopt -s histappend
and
# save history after each command instead of logout
PROMPT_COMMAND='history -a;'${PROMPT_COMMAND}
in your ~/.bashrc
You might also want to add this, too:
# don't put duplicate lines in the history. See bash(1) for more options ... and ignore same sucessive entries.
export HISTCONTROL=ignoredups
#
export HISTCONTROL=ignoreboth
"I think I am a fallen star. I should wish on myself."
Your data is corrupt: only the current sig is ever shown.
Shop as usual. And avoid panic buying.
More awesomely, if you have found something in your history with ^R or up arrow or whatever, then you can press ^O to "execute this line and put the next line in the history onto the command line". Thus:
./foo
vi foo.c
make
^Rvi^O^O^O^O^O^O^O^O^O^O^O^O^O^O
and so on.
For recent versions:
sudo -i
shorter
Mir tut es leid, Menschen daß Einfältigfehlersuchenbaumfolgendenaffen sind.
in bash, esc-. is a fantastic shortcut
I think you missed a '$' before the open parenthesis, it should be:
SHELLID=$(echo `tty` | sed 's!/!.!g')
Also, you could replace "echo `tty`" with simply "tty":
SHELLID=$(tty | sed 's!/!.!g')
Yeah. tail -f is amazing. Other big time savers:
-watch (reruns last comand at set interval)
-ctrl+z and then %(bg # goes here) & (stops current process and resumes it in background
-using tab instead of typing out file paths
- pipe redirects such as > and | (lets you put stuff in new places)
lol: You see no door there!
One of the most timesaving things I ever did was to replace the default sh or bash with zsh.
zsh has so many features, it would be impossible to list them all here. In fact, I can't claim to know them all, but everybody takes what works for them.
Suffice to say that the completion, iteration, history and redirection tools are second to none if you're as lazy a typist as I am.
It uses different, non-Python syntax, but I find Fish useful.
(posted with pbcopy)
503 sudo apt-get install xclip
504 echo xclip -in -selection clipboard > bin/pbcopy
505 chmod ug+x bin/pbcopy
506 echo xclip -o -selection clipboard > bin/pbpaste
507 chmod ug+x bin/pbpaste
508 history | pbcopy
"Be grateful for what you have. You may never know when you may lose it."
Well, unless you're already root, your command will fail with a permission denied error since the > redirect will run with your user permissions, not with sudo permissions.
So, in that case yes, sudo will prevent an "Oh sh*t!" moment.
Did you know that gullible is not in the dictionary?
I don't get it. You told him to give rm an absolute path, it doesn't matter where he was.
Shell built-in? news to me as I have it instaled on /usr/bin/
My post obviously isn't an actual output but my attempt at a koan. As koan's are supposed to disruput your cognitive process so one can percieve reality as such. Of course you may think it is a sucky koan, but an attemp at least it is.
You can Mod if Funny now :'(
Diff works fine with ssh.
ssh $remote_system cat remotefile | diff - localfile
cat localfile | ssh $remote_system diff - remotefile
That's what sudo -i is for.
bash#set -o vi
also
$ls -tgo |less
shows modified files first, useful for webmasters
Harah for vi mode!
'diff' - compare two files, list differences
'tr' - text replace... replaces all instances of a character in the input stream with a different one in the output.
'touch' - update timestamps on a file, or create it if it's not there
At my last job I dealt with a lot of HIPAA compliant medical files... All tilde delimited with no endlines. I ended up writing a bunch of perl scripts that piped the files through tr to replace tildes with endlines, then do something useful such as grep, or parse the files with regexes. Perl also has special variables for the field record seperators, which you can set to change the endline character that it reads ( $/ ) and writes ( $\ ). If you're ever working with delimited files with no endlines, this can be a lifesaver... just set both variables to your delimiter, and it handles all the conversion for you.
This might be horrendously ugly, but I use it all the time, normally in pairs. One example is to grab file extensions in a bourne-shell (not bash) compatible way
as in:
EXT=`echo $FILE | rev | cut -f 1 -d '.' | rev`
I know I know there are shell builtins for stuff like this for all recent shells. But why would you want to fuss with those.
Not by me! Sharing root passwords was _nasty_, and sudo provided much better logging of who was going in as root and forcing them to use their own passwords, not a root password.
Another 'du' variant:
du -mb | sort -rsg | less
Gets the size of all subdirectories relative to `pwd`, writes the size in blocks and sorts them from big to small. Very useful to find deeply nested directories stuffed with old and forgotten .iso's of Debian Potato.
Damn you Google ! Damn you and your lousy "exact search" ! Exact search my a** !
actually ignoreboth ignores duplicates and lines which begin with a space.
"Freiheit ist immer auch die Freiheit des Andersdenkenden" - Rosa Luxemburg, 1871 - 1919
Well, perhaps it depends on your distro. Some shells could have it built-in.
tail --follow=name --retry --max-unchanged-stats=5 Is good for log files that periodically restart and rename the old ones.
This is the best restaurant I ever eat in
A NeXT consultant showed me this:
mv /some/long/path/{old,new}file.blah
The {,} notation expands the containing word to a space-separated list obtained by substituting in each thing in the {}, giving for the above:
mv /some/long/path/oldfile.blah /some/long/path/newfile.blah
Great for mv, cp, ln, diff, cmp.
Free On-Line Dictionary of Computing http://foldoc.org/
Pshaw! All 1337 sysadmins just live as root!
Yes, but all the really stupid ones do as well.
Suppose you did this: ls -la filename, then you can do this: man !:0 which converts the !:0 into the zeroth word on the previous command, namely ls. So man !:0 would be man ls. Similarly, !:1 changes to -la, and !:2 is filename. You may also like !:1* or !:2*. !:1* would be the first word and all after it, !:2* is the second word and all after it. So !:1* changes to -la filename in this case. There is also !:0-2 for a range of words. Here is an example:
More information can be found in the HISTORY EXPANSION section of the bash manpage. Specifically, the Word Designators subsection. Enjoy!
in ~/.screenrc you can remap pretty much all the keys, including the control key. I've set mine to '`', and it works like a charm.
eject is a useful tool, If you have a rack of servers all alike and you need to identify one of them . Some servers have blinking lights etc. but mine had no audio nor lights. But it had a CD tray.
I simply put eject and "eject -t" in a loop and go look in the server room -- the hyperactive server is the one I was looking for.
http://slashdot.org/submission/1062723/Cheap-mobile-data-plan?art_pos=2
The rev command has got to be one of the most useless Unix commands I've ever come across.
That's crazy talk. I use rev all the time in shell scripts. Especially if I need the last bit of information in a line of unpredictable length. I''m so grateful for the core-utils.
(Some of these might have been mentioned)
Bash foo:
# Make my prompt "pretty" colours and set the xterm title bar to useful things at every command. Also make the continuation prompt blue rather than '> ' so I can cut and paste
PS1='\[\033[00;31m\]$USER\[\033[00;33m\]@\[\033[00;32m\]\h\[\033[00;00;00m\]:\[\033[00;34m\]\w\[\033[00;00;00m\]\$ '
PS2='\[\033[00;34m\]'
# Tell me if something worked
random_command && echo yes || echo no
# Completions:
# commands which should complete to a command
complete -A command which
# commands which should complete to a shell variable
complete -A file -A variable unset
complete -A file -A variable export
# commands which should complete to a word list and files
complete -A file -W "commit diff remove update status annotate log" cvs
complete -A file -W "all install depend clean" make
complete -A file -W "all install depend clean" pmake
# C-d twice to log out
IGNOREEOF=1
# Avoid tmp files
join <(sort file1) <(sort file2)
# Other things
shift-insert to paste from the clipboard in terminals
history > ~/docs/stuff_i_just_did_so_i_dont_forget
less -S for wide files
strace / ptrace / truss
pushd/popd
--oik
Here we have 5 people with root access on our web server. Who do you blame if root deletes /var/www?
With sudo I know exactly who to blame.
The reason pkill uses -v to negate the match is because it is a variation on the pgrep command, which is used to grep for processes. So, its options are much more like grep.
So, what option does grep use to negate the match?
"Alcohol, Tobacco, Firearms, and Explosives" should be a convenience store, not a government agency.
I'm guessing IHBT, but here's an explanation for those who don't quite get it:
He typed: at midnight `shutdown -r now`
He meant to type: at midnight "shutdown -r now"
The "at" command schedules the command in quotes to run at midnight. Putting backquotes around the command, as he actually typed, causes the command to be run immediately.