The command-line is the interactive interface to your shell.
100
votes
3answers
5k views
What's the difference between $(stuff) and `stuff`?
Running top -p $(pidof init) and top -p `pidof init` gives the same output. Are these two ways of doing the same thing, or are there differences?
86
votes
16answers
39k views
Repeat a Unix command every x seconds forever
There's a builtin Unix command repeat whose first argument is the number of times to repeat a command, where the command (with any arguments) is specified by the remaining arguments to repeat. For ...
75
votes
13answers
10k views
How to do integer & float calculations, in bash or other languages?
Using echo "20+5" literally produces 20+5
What command can I use to get the actual sum, e.g. 25 in this case.
Also, what's the easiest way to do it just using bash for floating point, e.g.
echo ...
55
votes
12answers
11k views
How to have tail -f show colored output
I'd like to be able to tail the output of a server log file that has messages like:
INFO
SEVERE
etc, and if it's SEVERE, show the line in red; if it's INFO, in green. What kind of alias can I ...
48
votes
21answers
4k views
Quick directory navigation in the terminal
I would like to frequently switch between directories that are in totally unrelated paths, for example /Project/Warnest/docs/ and ~/Dropbox/Projects/ds/test/.
But I don't want to type cd ...
44
votes
10answers
4k views
How to grep a specific line _and_ the first line of a file?
Assuming a simple grep such as:
$ psa aux | grep someApp
1000 11634 51.2 0.1 32824 9112 pts/1 SN+ 13:24 7:49 someApp
This provides much information, but as the first line of the ps ...
44
votes
8answers
2k views
Remember a half-typed command while I check something
I often find myself in the following position: I've started typing a long command at the bash prompt, but half-way through I find out I need to check something with another command. This is a problem ...
43
votes
6answers
10k views
Keep SSH Sessions running after disconnection
I sometimes have long running processes that I want to kick off before going home, so I create a SSH session to the server to start the process, but then I want to close my laptop and go home and ...
41
votes
3answers
2k views
Why is `--human-readable` needed and not default?
Several command line tools use the -h or --human-readable option to print file size in a human readable format (i.e., 36G vs 37550836).
Why is this option needed and not the default?
Aren't these ...
38
votes
6answers
3k views
When is xargs needed?
The xargs command always confuses me. Is there a general rule that can help me figure out when I need it?
Consider the two examples below:
$ \ls | grep Cases | less
prints the files that match ...
30
votes
2answers
6k views
What does “--” (double-dash) mean?
I have seen -- used in the compgen command.
For example:
compgen -W "foo bar baz" -- b
What is the meaning of the --.
29
votes
3answers
892 views
How can I cd to a directory just by typing the directory's name?
I either had this somewhere 20 years ago or I dreamed about it.
Basically:
If if type blobblob I get
blobblob: command not found
Fair enough.
I would like it so that when my shell gets those ...
29
votes
4answers
13k views
How can I close a terminal without killing the command running in it?
Sometimes I want to start a process and forget about it. If I start it from the command line, like this:
redshift
I can't close the terminal, or it will kill the process. Can I run a command in ...
26
votes
7answers
2k views
How do I delete a file whose name begins with “-” (hyphen a.k.a. dash or minus)?
How do you remove a file whose filename begins with a dash (hyphen or minus) -? I'm ssh'd into a remote OSX server and I have this file in my directory:
tohru:~ $ ls -l
total 8
-rw-r--r-- 1 me ...
26
votes
6answers
4k views
How can I find broken symlinks
Is there a way to find all symbolic links that don't point anywere?
find ./ -type l
will give me all symbolic links, but makes no distinction between links that go somewhere and links that don't. ...
24
votes
8answers
3k views
how do you sort du output by size?
How do you sort du -sh /dir/* by size? I read one site that said use | sort -n but that's obviously not right. Here's an example that is wrong.
[~]# du -sh /var/* | sort -n
0 /var/mail
1.2M ...
22
votes
6answers
8k views
How can I edit multiple files in VIM?
I know I can open multiple files with vim by doing something like vim 2011-12*.log, but how can I switch between files and close the files one at a time? Also, how can I tell the file name of the ...
22
votes
3answers
3k views
What is the difference between Halt and Shutdown commands?
What is the difference between the halt and shutdown commands?
21
votes
5answers
6k views
How can I move files and view the progress (e.g. with a progress bar)?
When moving large directories using mv, is there a way to view the progress (%)?
The cp command on gentoo had a -g switch that showed the progress.
21
votes
6answers
2k views
Linux tools to treat files as sets and perform set operations on them
Does anyone know of any linux tool specifically designed to treat files as sets and perform set operations on them? Like difference, intersection, etc?
21
votes
6answers
9k views
Markdown Viewer
I found a file formatted with Markdown. Could you guys suggest what viewer that I could use to view this type of files? Hopefully one without gui (if it's possible)
Update
I was actually looking for ...
20
votes
4answers
963 views
Is there a one-liner that allows me to create a directory and move into it at the same time?
I find myself repeating a lot of:
mkdir longtitleproject
cd longtitleproject
Is there a way of doing it in one line without repeating the directory name? I'm on bash here.
20
votes
2answers
885 views
Why is bash's prompt variable called PS1?
The environment variable for the bash prompt is called PS1 (usually set in ~/.bashrc). What does PS1 stand for? Is there a PS2?
20
votes
3answers
3k views
How can I “relink” a lot of broken symlinks?
I have a directory tree which has a bunch of symbolic links to files under /home... however, I have moved /home to /mnt/home and need a way to "relink" all of the symlinks. Does such functionality ...
19
votes
3answers
14k views
18
votes
4answers
2k views
Why do we use “./” to execute a file?
Why do we use ./filename to execute a file in linux?
Why not just enter it like other commands gcc, ls etc...
18
votes
4answers
600 views
Are Linux utilities smart when running piped commands?
I was just running a few commands in a terminal and I started wondering, does Unix/Linux take shortcuts when running piped commands?
For example, let's say I have a file with one million lines, the ...
18
votes
4answers
569 views
What should I use when cut doesn't cut it?
I have a file cities like this:
[1598] San Diego, US (inactive)
[4517] St Louis, US (inactive)
[6346] Orlando, US (inactive)
I want to cut out the city names, so that I have:
San Diego
St Louis
...
18
votes
3answers
704 views
Can other users view the arguments passed to a command?
If I invoke a command with arguments like so:
bob@bob-pc:~$ command -arg1 -arg2
...can other users view the arguments passed to the command?
18
votes
6answers
473 views
Why is aliasing over standard commands not recommended?
For example, a common alias I've seen in the ~/.bashrc file (or equivalents) is
alias rm='rm -i'
However, I've seen people recommend against this because
the alias might not exist on another ...
17
votes
6answers
2k views
How to understand what's taking up space?
I'm looking for a linux alternative to WinDirStat. I would like to know what is taking up space on my hard drives.
A program that works on console and doesn't require a UI is preferred .
17
votes
5answers
691 views
Difference between “. myscript” and “./myscript” [duplicate]
I am confused by "one only dot - space - shell script name" (like . myshellscript) and "path to shell script" (like ./myshellscript) commands.
What for they are? I noticed the command . myshellscript ...
17
votes
10answers
4k views
How do I reuse the last output from the command line?
This is a noob question, but I'd like to know how to reuse the last output from the console, ie:
pv-3:method Xavier$ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
...
17
votes
1answer
909 views
Should the usage message go to stderr or stdout?
Should the usage message which is printed with e.g.
command -?
of a Unix command go to stderr or stdout, and why? Should it go to the same place if the user makes a mistake with an option?
16
votes
5answers
2k views
Why is echo a shell built in command?
$ which echo
echo: shell built-in command.
$ which ls
/bin/ls
$ which cat
/bin/cat
Why is echo not an independent utility like ls, ps, cat etc? Why is it shell specific? Any good reasons?
16
votes
6answers
633 views
How stable are Unix shell “stdin/stdout APIs”?
grepping, awking, sedding, and piping are day-to-day routine of a user of any Unix-like operating system, may it be on the command line or inside a shell script (collectively called filters from now ...
16
votes
4answers
2k views
How to echo a bang!
I tried to create a script by echo'ing the contents into a file, instead of opening it with a editor
echo -e "#!/bin/bash \n /usr/bin/command args" > .scripts/command
The output:
bash: ...
16
votes
4answers
6k views
What is the mknod command used for?
I just started using Ubuntu as my main OS and I wanted to learn about things I should not do, and learn by the bad things people have done in the past. I came across these email about horror stories ...
16
votes
2answers
291 views
Is there a standard Unix command to check English verb conjugation?
Having recently come across wordlist and wordnet, two great discoveries on their own, I'm now looking for a similar tool, if simpler, that will take the bare infinitive of a verb and return the simple ...
15
votes
3answers
4k views
How does the “tail” command's “-f” parameter work?
$ tail -f testfile
the command is supposed to show the latest entries in the specified file, in real-time right? But that's not happening. Please correct me, if what I intend it to do is wrong...
I ...
15
votes
3answers
2k views
How do I send stdin to the clipboard?
Is there functionality in unix that allows for the following:
echo "Some Text" | copy-to-clipboard
15
votes
1answer
347 views
Is there a standard command that always exits with a failure?
I want to test my script with a command that fails. I could use an existing command with bad arguments. I could also write a simple script that immediately exits with a failure. Both of these are easy ...
15
votes
6answers
2k views
Command-line-friendly full-text indexing?
Is there such a thing as a full-text indexing engine, that can be queried from the command line and ideally wouldn't require using a gui at all ?
I'm especially interested in indexing my ebooks and ...
14
votes
7answers
8k views
Do we have an undo in Linux?
I renamed a few files in one batch script. Is there a way to undo the changes without having to rename them back?
Does Linux provide some native way of undoing?
14
votes
4answers
4k views
Can't pipe into diff?
I wanted to be clever and compare a remote file to a local file without downloading it. I can get the contents of the remote file by
ssh user@remote-host "cat path/file.name"
However, piping that ...
14
votes
8answers
545 views
How to tell what type of filesystem you're on?
Is there a command to tell what type of filesystem you're using?
14
votes
5answers
8k views
Split pages in pdf
I have a scanned pdf file which has scanned two pages on one virtual page (page in pdf file).
The resolution is with good quality. The problem is I have to zoom when reading and drag from left to the ...
14
votes
4answers
22k views
How to overwrite target files with mv?
I have a ton of files and dirs in a subdirectory I want to move to the parent directory. There are already some files and dirs in the target directory which need to be overwritten. Files that are only ...
14
votes
4answers
4k views
How can I send stdout to multiple commands?
There are some commands which filter or act on input, and then pass it along as output, I think usually to stdout - but some commands will just take the stdin and do whatever they do with it, and ...
14
votes
1answer
246 views
Make program first read from pipe, then from keyboard
Consider the interactive program interactive. I have to run this program fairly frequently, and each time I run it the first few commands are the same. Obviously, having to type those commands over ...
