Tag Info

Hot answers tagged

139

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


76

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

Command lines are not just available in history. They are also available, for example, in the output of ps -ocmd or through the /proc filesystem. (/proc/<pid>/cmdline) which is where ps reads them. Also, users' home directories are often world- or group- readable; you can make the history file only user-readable, but that might not survive deletion ...


37

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


34

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


32

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


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.


28

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


24

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


24

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


23

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


23

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


21

more more is an old utility. When the text passed to it is too large to fit on one screen, it pages it. You can scroll down but not up. Some systems hardlink more to less, providing users with a strange hybrid of the two programs that looks like more and quits at the end of the file like more but has some less features such as backwards scrolling. This is ...


21

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


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


20

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


19

Note that the recently (June 2013) released gzip-1.6 "accepts the --keep (-k) option, for consistency with tools like xz, lzip and bzip2. With this option, gzip no longer removes named input files when compressing or decompressing". Excerpt from the man page: -k --keep Keep (don't delete) input files during compression or decompression. So, ...


17

In general this should be fine to do it this way. When you click the "X" to close the terminal window, that is sending a "signal" from your desktop (GNOME, KDE, etc.) to the terminal application, telling it to shut itself down. Since you're running MATLAB in this shell it's considered a child process to the terminal application. So part of the ...


17

If you have bash 2.04 or above with the /dev/tcp pseudo-device enabled, you can download a file from bash itself. Paste the following code directly into a bash shell (you don't need to save the code into a file for executing): function __wget() { : ${DEBUG:=0} local URL=$1 local tag="Connection: close" local mark=0 if [ -z "${URL}" ]; ...


17

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


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


16

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


15

Passwords on the command line are just a bad idea all the way around. In addition to the methods discussed in the other answers: /proc process list (ps) user's history file User commands can show up in these locations as well: audit logs /var/log/* In addition user's commands can also show up when users login between systems, so in general it's a bad ...


15

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.


14

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


13

I assume that you have the process ID in pid. Most methods on most systems will require that the shell you're doing this from is running as the same user as the target process (or root). On Linux and Solaris and perhaps some other System V unices: cd /proc/$pid/cwd && pwd On Linux (except embedded systems where readlink is not available) but not ...


13

Your shell doesn't every time do a cd to the path that it was in during the last command, before executing the next command. You deleted the current directory and created a directory with the same name, which is not the same directory, just something with the same name/path. File browsers like Nautilus and Windows Explorer normally "go up" the directory ...


12

The window title in a terminal is set by control characters embedded in the output of whatever is running in the terminal. ssh is oblivious to this as it merely passes whatever characters are generated on the remote end back to the client's stdout. Usually most UNIX/Linux systems which "set the window title" do this by embedding the control characters in the ...


12

delete 100 lines forward from (including) the current one repeat dd (delete current line) 100 times: 100dd delete from current line to 99 lines forward d99j delete 100 lines backwards from (including) the current one d99k delete lines in a specific range by line number :1,100d delete lines in a range beginning with the current line :.,.+99d ...



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