Tag Info

Hot answers tagged

24

Use -- on every command. $ ls -la total 32 drwxr-xr-x 3 richard richard 512 Jul 28 15:44 . drwxr-xr-x 3 root wheel 512 Jul 6 17:10 .. $ mkdir -- -A $ ls -la total 36 drwxr-xr-x 2 richard richard 512 Jul 28 15:44 -A drwxr-xr-x 4 richard richard 512 Jul 28 15:44 . drwxr-xr-x 3 root wheel 512 Jul 6 17:10 .. $ cd -- -A $ ls $ pwd ...


14

Do you have access to the sda2-backup...gz file? Sudo only works with the command after it, and doesn't apply to the redirection. If you want it to apply to the redirection, then run the shell as root so all the children process are root as well: sudo bash -c "dd if=/dev/sda2 | gzip > /media/disk/sda2-backup-10august09.gz" Alternatively, you could ...


14

This is actually dependent on your shell. Quotes (either kind) are primarily meant to deal with whitespace. For instance, the following: grep hello world file1 will look for the word "hello" in files called "world" and "file1", while grep "hello world" file1 will look for "hello world" in file1. The choice between single or double quotes is only ...


12

The command df(1) takes one or more arguments and will return the mountpoint and device on which that file or directory exists, as well as usage information. You can then use the path or device to look up the filesystem type in the output of mount -v or similar. Unfortunately, the output format of both df and mount are system-dependent; there is no ...


11

You can put ./ in front of the file -- that way rm or rmdir won't behave as though the filename is an option flag. You can also issue the option -- which tells rm to act as though everything after the -- is a filename and that it should not process any more options. There may be funky older versions of rm that don't obey that, though my zoo of antique ...


11

In the first example, the redirection is happening in your current shell and not in the sudo subshell. So sudo is executing echo "search foo.bar.baz" and returning the result to your current shell, which then tries to write it to /etc/resolv.conf. You could make the first example work by invoking bash directly as your sudo command: sudo bash -c "echo ...


10

The best way is to run screen, execute your command, then detach using ^A, D. When you ssh into your machine again, run screen -r and your session will be reattached just as you left it. Screen can also do much more, check out the man page to see what's possible.


8

Haven't tried this one out yet. But if this is current is looks like someone already wrote the library you can preload with libfaketime. The basic usage is: user@host> LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="-15d" date Mon Nov 8 12:01:12 CEST 2007 You can use ltrace to make sure all the time functions your application uses are covered.


8

Sounds like you have php registered with binfmt_misc. Check out the man page on the subject: binfmt_misc.txt You'll want to unregister the php binfmt_misc handler by echoing -1 to it (must be root). It will be listed in /proc/sys/fs/binfmt_misc/ if this is your issue. As a warning, this could break other stuff on the system. For instance, if another PHP ...


8

You probably want /bin/bash unless you need to use /bin/sh, /bin/sh is more restricted. So if you are using bash: Like so: if [[ -e filename ]]; then echo 'exists' fi If your filename is in a variable, then use the following, the double quotes are important if the file has a space in it: if [[ -e "$myFile" ]]; then echo 'exists' fi If you ...


7

With bash, you can do this: init # do the preamble setup of script A scriptB & # start in background scriptC & # start in background scriptD & # start in background wait # wait for all background jobs to finish cleanup # do the cleanup part of script A


7

James is correct, but to add some more data, I think that the best way to think about it is as arguments to the command: do you intend "hello" and "world" to be two arguments or "hello world" to be one argument. Also, doublequotes allow interpretation of more than just variables. Exactly what depends on your shell, but check into history expansion, brace ...


7

OLDPWD is not set, because you have't changed directory [dave@odessa ~]$ cd - -bash: cd: OLDPWD not set [dave@odessa ~]$ cd /tmp [dave@odessa tmp]$ cd - /export/home/dave [dave@odessa ~]$ cd /tmp [dave@odessa tmp]$ echo $OLDPWD /export/home/dave cd without any arguments will chdir to $HOME [dave@odessa tmp]$ echo $HOME /export/home/dave [dave@odessa ...


6

take a look at rdiff-backup. it will not keep replicas of unchanged files, just the 'diffs'. if you want to keep on copying - use rsync rather than cp and take a look at syntax of exclude directive eg as described here. do remember to verify if your backups work [especially with rdiff or any other 'advanced' backup - verify the repository, try restore ...


6

type cd tells us that cd is a shell builtin man sh tells us what you found out: If a single dash is specified as the argument, it will be replaced by the value of OLDPWD. The internal implementation of cd in the shell does a chdir(2) -syscall.


6

You can compare files remotely using ssh: $ ssh -p 2022 localhost "cat /remote_path" | diff - /local_path $ ssh -p 2022 localhost "cat /etc/lsb-release" | diff - /etc/lsb-release 2,4c2,4 < DISTRIB_RELEASE=10.10 < DISTRIB_CODENAME=maverick < DISTRIB_DESCRIPTION="Ubuntu 10.10" --- > DISTRIB_RELEASE=10.04 > DISTRIB_CODENAME=lucid > ...


6

grep SESSNUM=4437 * Grep normally returns thing in order. Are you sure you are getting the results from the correct log file? Does it work correctly if you specify the logfile you want instead of just *? Correction! There should only be one file in the directory that contains the session number, but I don't necessarily know which one when I'm ...


5

I like to use rsync for this purpose. For example, on ServerA run: rsync -avnc --delete /path/to/dir/ serverB:/path/to/dir/ You can remove the -c switch if you don't need to do a checksum comparison of the files. Without it rsync will assume they are the same if they have the same size and timestamps. Note the trailing slashes on each of the paths. ...


5

On modern systems you should be able to look in /etc/lsb-release mojo-jojo david% cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=9.10 DISTRIB_CODENAME=karmic DISTRIB_DESCRIPTION="Ubuntu karmic (development branch)" This should be the LSB mandated way of finding out the distribution across different Linux distributions. You should not rely on ...


5

Something like this might work: find -L / -samefile /path/to/your/file Obviously you'll need to replace /path/to/your/file with the file in question. A brief explanation: -L = treat symbolic links as if they were the file to which they refer / = search from the root of the file system -samefile = find the files that are the same as this one


5

You can try links http://www.example.com or lynx http://www.example.com You can also try links -g to put it into "graphics" mode but I don't think this will work over SSH.


5

There's a package called "screen" that needs to be installed on the host you're logged into. This has nothing to do with putty, or ssh - this is the way Unix shells work. When you disconnect a shell, you're logged off, and all your processes get a HUP signal. Most (all) processes shut down. "Screen" makes your shell continue running, so you may reconnect ...


5

The only reason that [[:digit:]] must be used is to support locales that use digits other than 0-9. For example Arabic-Indic Numerals: ٠١٢٣٤٥٦٧٨٩ (Unicode U+0660 through U+0669). Otherwise for the Hindu-Arabic numerals 0123456789, [0-9] works equally as well as [[:digit:]].


4

# time grep -oE '[[:digit:]]' /etc/services ... real 0m0.029s user 0m0.017s sys 0m0.013s # time grep -oE '[0-9]' /etc/services ... real 0m0.029s user 0m0.016s sys 0m0.012s I could probably write a quick script to average them, and I bet I'd find that the averages are identical, but it certainly gives you the idea.


4

Edit: I'm not clear if you are talking about cd --, or cd -- -. So, I'll try to answer both questions. cd -- (with no directory) will act the same as cd (with no directory). You will be returned to your home directory. cd -- will not switch you back to the previous working directory. stefanl@host:~ $ cd tmp stefanl@host:~/tmp $ cd -- stefanl@host:~ $ cd ...


4

Yes! You should background the process and disown it. So, if I wanted to run the command "foo", I'd do nohup foo & && disown. The nohup keeps it from dying when SIGHUP is sent to it and sends the output to a file, and disown removes the parent reference so it doesn't die when the spawning shell does.


4

You can use the write command to send messages to a specific user instead of to everybody. You can send them over the network using whatever login credentials you already have, usually over ssh like this: ssh youruse@hostname write username to send username@hostname a message.


4

A better approach is to test that what you want to do is possible rather than relying on what the distribution is. For example my Ubuntu box claims it is "squeeze/sid". If you want to install something via dpkg, check dpkg is where you expect it an is executable. If you want to modify the networking setup? Check that /etc/networking/interfaces exists. Check ...


4

There was a script someone wrote in another question: find / -type d -printf "chmod %m %p \n" > reset_perms.sh that forced the permissions down. I'd like to compare and output the changes rather than force them down. Instead of printing out the commands to run change permissions, simply adjust the printf to spit out the uid, gid, mode, and ...


4

There is a maximum limit to how long an argument list can be for system commands -- this limit is distro-specific based on the value of MAX_ARG_PAGES when the kernel is compiled, and cannot be changed without recompiling the kernel. Due to the way globbing is handled by the shell, this will affect most system commands when you use the same argument ...



Only top voted, non community-wiki answers of a minimum length are eligible