Hot answers tagged

110

du -sh is a good place to start. The options are (from man du): -s, --summarize display only a total for each argument -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) To check more than one directory and see the total, use du -sch: -c, --total produce a grand total


53

The order of switches is free, but -f has a mandatory argument which is the file that tar will read/write. You could do tar -zf foo.tar.gz -xv and that will work, and has your requirement of a non-specific order of switches. This is how all commands that have options that have arguments work.


42

To find out about a key binding. In bash: $ bind -p | grep -a '{' "\e{": complete-into-braces "{": self-insert $ LESS='+/complete-into-braces' man bash complete-into-braces (M-{) Perform filename completion and insert the list of possible com‐ pletions enclosed within braces so the list is available to the shell (see ...


36

Just use the du command: du -sh * will give you the size of all the directories,files etc in current directory in human readable format. You can use the df command to know the free space in the disk: df -h .


33

I would highly recommend running Linux in a VM. All the software is available freely to download and there is no practical difference between running in a VM and running natively for the purposes of learning the command line. Furthermore, Linux command line mostly consists of bash + GNU coreutils, which is very different from BSD Unix (and OS X is a ...


32

IFS stands for "internal field separator". It is used by the shell to determine how to do word splitting, i. e. how to recognize word boundaries. Try this in a shell like bash (other shells may handle this differently, for example zsh): mystring="foo:bar baz rab" for word in $mystring; do echo "Word: $word" done The default value for IFS consists of ...


29

Adding & spawns a background process. If you write a; b, it will run command a, wait for it to finish, then run command b, in sequence. If you write a & b, it will spawn a as a background process. It will not wait for it to finish, and it will start running b immediately. It will run both at once. You can see what it does by experimenting in the ...


28

root is the superuser account on the system — it (basically) has all privileges. Many systems are configured so that you can use the sudo command in front of another command to run that command "as root" — that is, as if you are the root user, with the same privileges. It is usually the case that you need root privileges to install system packages, which is ...


27

You can use the echo or find commands instead of ls: echo * or: find -printf "%M\t%u\t%g\t%p\n"


26

The tool to display inode detail for a filesystem will be filesystem specific. For the ext2, ext3, ext4 filesystems (the most common Linux filesystems), you can use debugfs, for XFS xfs_db, for ZFS zdb. For btrfs some information is available using the btrfs command. For example, to explore a directory on an ext4 filesystem (in this case / is dev/sda1): # ...


25

From the findutils find manpage: If no expression is given, the expression -print is used (but you should probably consider using -print0 instead, anyway). (-print is a find expression.) The POSIX documentation confirms this: If no expression is present, -print shall be used as the expression. So find . is exactly equivalent to find . -print; ...


25

Ctrl+4 sends ^\ Terminals send characters (or more precisely bytes), not keys. When a key that represents a printable character is pressed, the terminal sends that character to the application. Most function keys are encoded as escape sequences: sequences of characters that start with the character number 27. Some keychords of the form Ctrl+character, and a ...


25

*.* only matches filenames with a dot in the middle or at the end. For example: abc.jpg def. * matches the filenames above, plus the names which don't have a dot at all. for example: data


24

You should understand that bash is just an execution environment. It executes commands that you call - it's not the business of the shell to even know what the command does, you can call any executable you want. In most cases, it's not even clear what an undo would do - for instance, can you "unplay" a movie? Can you "unsend" an e-mail? What would "undo ...


24

You could use named pipes (http://linux.die.net/man/1/mkfifo) on the command line of tee and have the commands reading on the named pipes. mkfifo /tmp/data0 /tmp/data1 /tmp/data2 cmd0 < /tmp/data0 & cmd1 < /tmp/data1 & cmd2 < /tmp/data2 & command -option1 -option2 argument | tee /tmp/data0 /tmp/data1 /tmp/data2 When command finishes, ...


24

You can also use the printf command, instead of echo: printf '%s\n' * printf is superior to echo in this situation in that echo does not respect the "double dash" (--) to signify the end of the argument list (on some systems, including Ubuntu 14.04 which is what I tested it on): llama@llama:~$ mkdir -p Misc/unix210948 llama@llama:~$ cd !$ cd ...


23

When using rm with both -i and -f options, the first one will be ignored. This is documented in the POSIX standard: -f Do not prompt for confirmation. Do not write diagnostic messages or modify the exit status in the case of nonexistent operands. Any previous occurrences of the -i option shall be ignored. -i Prompt for ...


22

a dual-use question! Either a Software Archaeologist or an Evil Hacker could use the answers to this question! Now, which am I? I always used to use ps -ef versus ps -augxww to find out what I was on. Linux and System V boxes tended to like "-ef" and error on "-augxww", vice versa for BSD and old SunOS machines. The output of ps can let you know a lot as ...


22

If you want to append to a file you have to use >>. So your examples would be $ md5sum file >> checksums.txt and $ sha512sum file >> checksums.txt


21

Commands run by at don't run in the terminal where they were registered. This wouldn't make sense in general: the terminal might not exist any more, or it might be in use by a different user. You may even have logged out by the time the command runs. Output from an at command is sent to you by email. That's local Unix email, not whatever external POP or ...


21

One way to achieve this is by modifying the .bashrc file. Simply place the following at the end of the .bashrc file. PS1="\n$PS1" To explain how this works, PS1 is the variable containing what should be displayed as the prompt. All this is saying is "set PS1 to the previous contents of PS1, with a newline character prepended". Putting it in .bashrc on ...


20

A shell script is an executable program. That's why type says that it is one. A shell script is as much an executable command as a perl script, a python script, a native ELF executable, a cross-architecture executable being executed by Qemu through Linux's binfmt_misc mechanism, etc. Any executable file is an executable command, it doesn't matter what ...


19

!1255:p Will do this ! is history recall 1255 is the line number :p prints but does not execute Then you can use up-arrow to get ther previous (unexecuted) command back and you can change it as you need. I often combine this with hg ("History Grep") - my favorite alias. $ alias hg # Maybe use hgr instead if you are a Mercurial CLI user. alias ...


18

You could use gnuplot for this: primes 1 100 |gnuplot -p -e 'plot "/dev/stdin"' produces something like You can configure the appearance of the graph to your heart's delight, output in various image formats, etc.


18

OS X is sufficient to learn the command line as it is a certified UNIX and conforms to POSIX. If you are looking at Linux specific command line book you have to keep in mind that the userland tools in OS X are derived from BSD while the tools on Linux are GNU and there are some subtle (and not so subtle) differences between them. If you want to learn ...


18

From man sh -c string If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with $0 It means your command should be like this: $ sh -c 'echo $0' foo foo Similarly: $ sh -c 'echo $0 $1' foo bar foo bar That was ...


17

With tr: echo "Thhiisss iisss mmyyy nameeee" | tr -s 'a-z' Explanation: The -s switch of tr "squeezes" repeat characters. As shown, the switch can be used with a range of characters: a to z.


17

You can use <M-.> (or <Esc>. if your Meta key is being used for something else), that is, Meta-dot (or <esc> dot), where Meta is usually the Alt key, to recall the last argument of the previous command. So, first you would type $ grep foo /usr/share/dict/american-english And then if you wanted to grep for something else, you would type $ ...


17

The attempt to use isoinfo comes from lesspipe, which is generally used as a helper for less via the LESSOPEN variable. Running LESSOPEN= less file.raw will open file.raw without interpretation.


16

It is a bad idea (to have strange characters in file names) but you could do mv somefile.txt "foo bar" (you could also have done mv somefile.txt "$(printf "foo\nbar")" or mv somefile.txt foo$'\n'bar, etc... details are specific to your shell. I'm using zsh) Read more about globbing, e.g. glob(7). Details could be shell-specific. But understand that ...



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