Hot answers tagged

80

What's the simplest way of hiding user input? Not displaying it! Hiding passwords when they're being typed is an old tradition. In makes sense from a security perspective in most contexts: if someone is looking over your shoulders, you don't want to make it easy to see what you're typing. (Some modern security guidelines e.g. 1 2 3 4 5 do recommend having ...


55

Using Bash, I would just visit the directories: $ cd /path/to/source/directory $ cd /path/to/destination/directory Then, I would use the shortcut ~-, which points to the previous directory: $ cp -v ~-/file1.txt . $ cp -v ~-/file2.txt . $ cp -v ~-/file3.txt . If one wants to visit directories in reverse order, then: $ cp -v fileA.txt ~- $ cp -v fileB....


54

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.


54

That's because bash remembered your command location, store it in a hash table. After you uninstalled node, the hash table isn't cleared, bash still thinks node is at /usr/local/bin/node, skipping the PATH lookup, and calling /usr/local/bin/node directly, using execve(). Since when node isn't there anymore, execve() returns ENOENT error, means no such file ...


48

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


48

convert, the ImageMagick utility used in Ketan's answer, also allows you to write something like convert xc:none -page Letter a.pdf or convert xc:none -page A4 a.pdf or (for horizontal A4 paper) convert xc:none -page 842x595 a.pdf etc., without creating an empty text file. @chbrown noticed that this creates a smaller pdf file. "xc:" means "X ...


38

Because that's the way we do things in *nix land. :) It gives a little bit of extra security by not displaying a bunch of asterisks. That way, someone who sees your screen can't see the length of your password. But I must admit it is a little bit scary not getting any feedback when you're entering a password, especially if you've got a bad keyboard. So ...


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


33

There is a way better way of achieving this: less +F <file> It'll show you the whole file, has the full power of less and will wait for new input. If you want to stop waiting for input, and read a specific part, you can stop it with ^C and resume with F. The F command is always available in less, if you decide to watch for changes while having a ...


32

tail lets you add -n to specify the number of lines to display from the end, which can be used in conjunction with -f. If the argument for -n starts with + that is the count of lines from the beginning (0 and 1 displaying the whole file, 2 indicating skip the first line, as indicated by @Ben). So just do: tail -f -n +0 filename If your log files get ...


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


28

Like the smallest possible GIF, the smallest possible blank-page PDF needs to be worked out by hand, because it's so small that unnecessary-but-harmless bits of metadata become a significant part of the file size, and compression actually makes things bigger. It also requires careful attention to the rules in the PDF specification about what bits of the ...


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

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


25

Essentially "because it's been done that way since manual typewriters". Really. A manual typewriter had a carriage on which the paper was fed, and it moved forward as you typed (loading a spring), and had a lever or key which would release the carriage, letting the spring return the carriage to the left-margin. As electronic data entry (teletype, etc) ...


25

You can use find. Assuming that you want only regular files, you can do: find /path/to/dir -type f > listOfFiles.list You can adjust the type parameter as appropriate if you want other types of files.


24

If you have convert (an ImageMagick utility) installed, you could do this: touch a.txt && convert a.txt -page Letter a.pdf


24

On a GNU system and if you have pv, you could do: cmd=' that command | to execute && as shell code' yes | pv -qL10 | xargs -n1 -P20 sh -c "$cmd" sh The -P20 is to execute at most 20 $cmd at the same time. -L10 limits the rate to 10 bytes per second, so 5 lines per second. If your $cmds become two slow and causes the 20 limit to be ...


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


22

You could do this: mv /longpath/longfile !#:1:h/morepath/ See https://www.gnu.org/software/bash/manual/bashref.html#History-Interaction !# is the current command :1 is the first argument in this command :h is the "head" -- think dirname /morepath/ appends that to the head and you're moving a file to a directory, so it keeps the same basename. If you ...


21

This is the one-liner that you need. No other config needed: mkdir longtitleproject && cd $_ The $_ variable, in bash, is the last argument given to the previous command. In this case, the name of the directory you just created. As explained in man bash: _ At shell startup, set to the absolute pathname used to invoke the ...


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


21

If both terminals belong to the same user, you can send your output to the virtual device that is used as the particular terminal's tty. So you can use the output from w, which includes the TTY information, and write directly to that device. ls > /dev/pts/7 (If the device mentioned by w was pts/7) Another option is to use the number of a process that ...


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


20

You can try to write in C: #include <unistd.h> #include <stdio.h> #include <string.h> int main(){ char buf[BUFSIZ]; int nread; size_t nfound=0; while((nread=read(0, buf, BUFSIZ))>0){ char const* p; for(p=buf; p=memchr(p,'\n',nread-(p-buf)); nfound++,p++) {;} } if(nread<0) { perror("Error"); return 1; } printf("%...


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 hg='...


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



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