Tag Info

Hot answers tagged


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


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


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)


Using cat Since your file is short, you can use cat. cat filename Using less If you have to view the contents of a longer file, you can use a pager such as less. less filename You can make less behave like cat when invoked on small files and behave normally otherwise by passing it the -F and -X flags. less -FX filename I have an alias for less ...


With GNU truncate: truncate -s 1M nullbytes would create a 1 mebibyte sparse files. That is a file that appears filled with zeros that doesn't take any space on disk. Without truncate, you can use dd instead: dd bs=1048576 seek=1 of=nullbytes count=0 (with some dd implementations, you can replace 1048576 with 1M) If you'd rather the disk space be ...


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


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


wget -qO- 'http://www.youtube.com/watch?v=Dd7dQh8u4Hc' | perl -l -0777 -ne 'print $1 if /<title.*?>\s*(.*?)\s*<\/title/si' You can pipe it to GNU recode if there are things like &lt; in it: wget -qO- 'http://www.youtube.com/watch?v=Dd7dQh8u4Hc' | perl -l -0777 -ne 'print $1 if /<title.*?>\s*(.*?)\s*<\/title/si' | recode html.. ...


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.


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


dmidecode -s system-product-name I have tested on Vmware Workstation, VirtualBox, QEMU with KVM, standalone QEMU with Ubuntu as the guest OS. Others have added additional platforms that they're familiar with as well. Virtualization technolgies VMware Workstation root@router:~# dmidecode -s system-product-name VMware Virtual Platform VirtualBox ...


In normal mode, do 100dd. dd deletes the current line. Prefacing that command with 100 causes it to repeat 100 times.


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


In case apt-get or dpkg needs rm and without rm a reinstallation is not posssible, then you can emulate rm with perl: cat > /bin/rm << "EOF" #!/usr/bin/perl foreach (@ARGV) { unlink $_ or warn "$@:$!"; } EOF chmod +x /bin/rm


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;"


Python imports a large number of files at startup: % python -c 'import sys; print len(sys.modules)' 39 Each of these requires an even greater number of attempts at opening a Python file, because there are many ways to define a module: % python -vv -c 'pass' # installing zipimport hook import zipimport # builtin # installed zipimport hook # trying ...


dd if=/dev/zero of=/var/tmp/nullbytes count=1 bs=1M


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


You can also try hxselect (from HTML-XML-Utils) with wget as follows: wget -qO- 'http://www.youtube.com/watch?v=Dd7dQh8u4Hc' | hxselect -s '\n' -c 'title' 2>/dev/null You can install hxselect in Debian based distros using: sudo apt-get install html-xml-utils. STDERR redirection is to avoid the Input is not well-formed. (Maybe try normalize?) ...


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


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.


There are 3 methods that I'm aware of: pwdx $ pwdx <PID> lsof $ lsof -p <PID> | grep cwd /proc $ readlink -e /proc/<PID>/cwd Examples Say we have this process. $ pgrep nautilus 12136 Then if we use pwdx: $ pwdx 12136 12136: /home/saml Or you can use lsof: $ lsof -p 12136 | grep cwd nautilus 12136 saml cwd DIR ...


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


With bash, you could use brace expansion mv blob/a_long_directory_name/{c/x.x,evenmore/y.y}


There are many ways to go about this. Method #1 - ps You can use the ps command to find the process ID for this process and then use the PID to kill the process. Example $ ps -eaf | grep [w]get saml 1713 1709 0 Dec10 pts/0 00:00:00 wget ... $ kill 1713 Method #2 - pgrep You can also find the process ID using pgrep. Example $ pgrep wget ...


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


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


The convention is that everything that starts with a - is an option. This collides with filenames that start with -. To work around this most commands recognize -- as an end-of-options sentinel. Everything after the -- will not be recognized as options, instead will be taken literally as filenames. For example cat -- --1 or rm -rf -- --1 Another ...


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


The good old perl rename: rename 's/(\d+)(\.jpg)/($1-1).$2/e' * [Remarks] Image numbers should be greater than 0. In case images are greater than 9 and have not leading 0s, use $(ls -v1 *) to avoid clobbering. Proposed by @arielf and noticed by @Graeme. When in doubt use also -v for verbose and -n for no-action.

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