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 ...


20

echo 'hello world' >> log.txt


15

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 ...


15

*.jpg expands to a list longer than the shell can handle. Try this instead find /home/ftpuser/public_html/ftparea/ -name "*.jpg" -exec cp -uf "{}" /your/destination \;


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 ...


13

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.


10

You disable it by adding the following line in your script: set -o noglob As an example, echo * your files and folders are shown here.. set -o noglob echo * *


8

You can put it into "": $ ls file1 file2 file3 file4 file5 file6 file7 file8 file9 $ Q='select * from table;' $ echo $Q select file1 file2 file3 file4 file5 file6 file7 file8 file9 from table; $ echo "$Q" select * from table;


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 ...


8

awk -F \| '{if ($2 != 05408736032) print}'


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

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

Use tail -n +X filename to print from the Xth line to end of file.


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

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


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

http://tldp.org/LDP/abs/html/fto.html


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 ...


6

You could use stat. The command stat --printf '%d' filename.txt will return the device number as hex/decimal.


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

If you use the -i option (and don't use the -v option), rsync will only print lines to STDOUT for any changes that were made. Depending on your script, this could look like if [ `rsync -i /dir1 /dir2 | wc -l` == '0' ]; then run_command; fi


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 > ...


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

I'm not sure what you are trying to do but bash is performing parameter expansion in your here document because the delimiter ENDOFFILE. If you were to change it to 'ENDOFFILE' bash would not expand.


5

This is one way: sed -n '3p' file Here's another: head -n 3 file | tail -n 1



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