Tag Info

Hot answers tagged

158

sudo touch /bin/rm && sudo chmod +x /bin/rm apt-get download coreutils sudo dpkg --unpack coreutils* And never again. Why didn't you used sudo with apt-get? Because the download command doesn't require it: download download will download the given binary package into the current directory. So, unless you are ...


91

debian and its derivatives (and probably most other distributions) come with busybox which is used in the initramfs. busybox bundles most core command line utilities in a single executable. You can temporarily symlink /bin/rm to /bin/busybox: ln -s busybox /bin/rm To get a working rm (after which you can do your apt-get install --reinstall coreutils). ...


46

just type: alias gb='cd /media/Dan/evolution' To make this setting permanent (so that it sticks after you restart or open another console) add this line to the file ~/.bashrc (assuming you use the bash as your default shell)


40

> is the default continuation prompt.That is what you will see if what you entered before had unbalanced quote marks. As an example, type a single quote on the command line followed by a few enter keys: $ ' > > > The continuation prompts will occur until you either (a) complete the command with a closing quote mark or (b) type ...


37

lynx has a "dump" mode, which you can use with watch: $ watch lynx https:/www.google.com -dump From man lynx: -dump dumps the formatted output of the default document or those specified on the command line to standard output. Unlike interactive mode, all documents are processed. This can be used in the ...


35

What you want to do is use a pipe and greps -Z option: Using GNU grep and mv grep -LZ -- Attachments * | xargs -0 mv -t target_directory The -Z combined with xargs -0 handles any filenames with special characters. Using BSD grep and mv (like on MacOS X) grep -L --null -- Attachments * | while IFS= read -r -d "" file; do mv "./$file" ...


34

Alternative to aliasing gb() { cd /media/Dan/evolution; } This defines shell function gb, which takes no arguments, and performs cd /media/Dan/evolution. As with other suggeststions, this can be added to ~/.bashrc


34

tac/grep Solution tac file | grep whatever Or a bit more effective: grep whatever < <(tac file) Time with a 500MB file: real 0m1.225s user 0m1.164s sys 0m0.516s sed/grep Solution: sed '1!G;h;$!d' | grep whatever Time with a 500MB file: Aborted after 10+ minutes. awk/grep Solution: awk '{x[NR]=$0}END{while (NR) print x[NR--]}' ...


33

If the first character of file name is printable but neither alphanumeric nor whitespace you can use [[:punct:]] glob operator: $ ls *.txt f1.txt f2.txt ♫abc.txt $ ls [[:punct:]]*.txt ♫abc.txt


33

You should use the at command: $ sudo at 6:45 [sudo] password for root: warning: commands will be executed using /bin/sh at> poweroff at> <EOT> Don't type the <EOT>, but press Ctrl+D at the second at> prompt. The significant advantage of using at over using shutdown with a TIME argument, is that it involves real, persistent, ...


29

I would say because it's hardly ever necessary to create an empty file that you won't fill with content immediately on the command line or in shell scripting. There is absolutely no benefit in creating a file first and then using I/O redirection to write to the file if you can do so in one step. In those cases where you really want to create an empty file ...


28

nohup read the man page for nohup usage. nohup is the way it's been done long since before screen, tmux, etc were invented. Example: nohup my_long_running_proc & Runs "my_long_running_proc", and any console (stdout/stderr) messages go into a file called "nohup.out" in the directory from which the command was started.


25

UPDATE (2014-02-02) Thanks to our very own @Anthon's determination in following the lack of this feature up, we have a slightly more formal reason as to why this feature is lacking, which reiterates what I explained earlier: Re: [PATCH] ls: adding --zero/-z option, including tests From: Pádraig Brady Subject: Re: [PATCH] ls: adding --zero/-z ...


25

Probably going to get my knuckles rapped for this, here's a hacky combination of bash brace expansion and eval that seems to do the trick eval {stat,file}" fileName;"


23

To me the "cd ../code" is a noop. I'm very interested into hearing why it isn't. Because files and directories are fundamentally filesystem inodes, not names -- this is perhaps an implementation detail specific to the filesystem type, but it is true for all the ext systems, so I'll stick to it here. When a new directory code is created, it is ...


23

You can use brace expansions: convert -trim -density 400 this_is_a_very_long_filename_of_my_pdf_file.{pdf,png}


21

With zsh, you can use anonymous functions: (){stat $1; file $1} filename With es lambdas: @{stat $1; file $1} filename You could also do: { stat -; file -;} < filename (doing the stat first as the file will update the access time). I'd do: f=filename; stat "$f"; file "$f" though, that's what variables are for.


20

You can use the !!:gs/search/replace/ notation to do what you want. This utilizes the global search & replace (:gs): before $ echo "harm warm swarm barm" harm warm swarm barm after $ !!:gs/arm/orn/ echo "horn worn sworn born" horn worn sworn born References The Definitive Guide to Bash Command Line History Caret search and replace in Bash shell ...


19

Using GNU grep for the colouring: color() { GREP_COLOR=$1 grep --color '.*'; } (tail -qf /var/log/syslog | color 31 & tail -qf /var/log/fail2ban.log | color 32 & tail -qf /var/log/nginx/error.log | color 33) Note that the first 2 are started in background. That means they won't be killed if you press Ctrl-C (shell explicitly ignore SIGINT for ...


19

You can use shutdown: sudo shutdown -h 06:45 & And to check it: ps -aux | grep shutdown If you want to cancel it: sudo shutdown -c This assumes of course that the shutdown time has already passed.


17

If you know that none if the file names contain new lines, tabs, spaces or glob combinations that may produce a match, this may be easier for a one off case: mv $(grep -L Attachments *) dest_dir


17

Yes, there is a big difference. && is short-circuiting, so the subsequent command would be executed only if the previous one returned with an exit code of 0. Quoting from the manual: expression1 && expression2 True if both expression1 and expression2 are true. On the other hand, a script containing expression1 expression2 would ...


17

sed Solution: sed -e 1b -e '$!d' file When reading from stdin if would look like this (for example ps -ef): ps -ef | sed -e 1b -e '$!d' UID PID PPID C STIME TTY TIME CMD root 1931 1837 0 20:05 pts/0 00:00:00 sed -e 1b -e $!d head & tail Solution: (head -n1 && tail -n1) <file When data is comming from a ...


17

In Bash, you can use Bash's built in string manipulation. In this case, you can do: > text="some text with spaces" > echo "${text// /}" sometextwithspaces For more on the string manipulation operators, see http://tldp.org/LDP/abs/html/string-manipulation.html However, your original strategy would also work, your syntax is just a bit off: > ...


15

Easy trick for alias in $(compgen -a); do type $alias; done


15

There are several options to do so: You can use a terminal multiplexer like screen or tmux. In screen, for example, the shortcut Ctrl+a - a, has the same functiononality as Alt+Tab in graphical environments: switch to the last screen. Or you use vim's internal function. Type :!command in vim's command mode. For example: :!ls -l. After the command ...


15

That will happen if you have an unclosed quote in your command. That's something like: $ echo "test here > > ... You can exit that mode by closing the quote (write a " or ', or whatever your open quote is). It could also be a brace-delimited block, a partially-complete for-do or while-do loop, or certain other constructs. You can also press Ctrl-C ...


15

Because builtins are part of the shell. Any bugs or history they have are bugs and history of the shell itself. They are not independent commands and don't exist outside the shell they are built in. The equivalent, for bash at least, is the help command. For example: $ help while while: while COMMANDS; do COMMANDS; done Execute commands as long as a ...



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