Most Popular
1500 questions
216
votes
5 answers
Precedence of the shell logical operators &&, ||
I am trying to understand how the logical operator precedence works in bash. For example, I would have expected, that the following command does not echo anything.
true || echo aaa && echo bbb
However, contrary to my expectation, bbb gets printed.…
Martin Vegter
- 69
- 66
- 195
- 326
216
votes
11 answers
Tool to monitor folder for new files and run command whenever new file is detected
How can I immediately detect when new files were added to a folder within a bash script?
I would like the script to process files as soon as they are created in the folder. Are there any methods aside from scheduling a cron job that checks for new…
norq
- 4,034
- 4
- 20
- 18
215
votes
9 answers
tar: Removing leading `/' from member names
root@server # tar fcz bkup.tar.gz /home/foo/
tar: Removing leading `/' from member names
How can I solve this problem and keep the / on file names ?
superuser
- 2,251
- 2
- 13
- 6
215
votes
9 answers
ssh-add complains: Could not open a connection to your authentication agent
I've been trying to get ssh-add working on a RaspberryPi running Raspbian.
I can start ssh-agent, when I do it gives the following output into the terminal:
SSH_AUTH_SOCK=/tmp/ssh-06TcpPflMg58/agent.2806; export SSH_AUTH_SOCK;
SSH_AGENT_PID=2807;…
Daniel Groves
- 2,253
- 2
- 14
- 5
215
votes
11 answers
How to check if a shell is login/interactive/batch
I think I understand the differences between an interactive, a login and a batch shell. See the following links for more help:
What is the difference between a 'Login' and an 'Interactive' bash shell (from the sister site: Server Fault)
Difference…
Amelio Vazquez-Reina
- 40,169
- 77
- 197
- 294
215
votes
9 answers
Move folder content up one level
I have a directory that is unpacked, but is in a folder. How can I move the contents up one level? I am accessing CentOS via SSH.
whatshakin
215
votes
5 answers
date command --iso-8601 option
This answer and comments mention --rfc-3339 and a "hidden" --iso-8601 option that I have used for a long time and now seems to be undocumented.
When did that option documentation get removed from the --help text?
Will the option go away anytime…
Angelo
- 2,159
- 2
- 11
- 7
214
votes
22 answers
Simple command line HTTP server
I have a script which generates a daily report which I want to serve to the so called general public. The problem is I don't want to add to my headaches maintance of a HTTP server (e.g. Apache) with all the configurations and security…
Cid
- 2,355
- 2
- 14
- 6
214
votes
8 answers
Why is looping over find's output bad practice?
This question is inspired by
Why is using a shell loop to process text considered bad practice ?
I see these constructs
for file in `find . -type f -name ...`; do smth with ${file}; done
and
for dir in $(find . -type d -name ...); do smth with…
don_crissti
- 79,330
- 30
- 216
- 245
214
votes
3 answers
How to install Desktop Environments on CentOS 7?
I have recently installed CentOS 7 (Minimal Install without GUI) and now I want to install a GUI environment in it.
How can I install Desktop Environments on previously installed CentOS7 without reinstalling it?
αғsнιη
- 40,939
- 15
- 71
- 114
214
votes
1 answer
Human readable memory sizes in top?
Is there an option in top to show memory sizes in human readable format?
Example:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
3960 phil 20 0 1347280 383112 30316 S 0.0 9.5 …
Philipp Claßen
- 4,689
- 7
- 29
- 41
214
votes
7 answers
delete line in vi
How can I delete a line in VI?
Here what I am doing right now:
Open up the terminal alt + ctrl + t
vi a.txt
I move my cursor to the line which I wan to delete, then what key-combination is should use to delete line in vi editor?
I-M-JM
- 2,251
- 2
- 14
- 5
214
votes
6 answers
Sort based on the third column
I'm facing a huge 4-columns file. I'd like to display the sorted file in stdout based on its 3rd column:
cat myFile | sort -u -k3
Is that enough to perform the trick?
user1058398
- 4,038
- 9
- 29
- 31
213
votes
8 answers
How to remove all empty directories in a subtree?
How can I remove all empty directories in a subtree? I used something like
find . -type d -exec rmdir {} 2>/dev/null \;
but I needs to be run multiple times in order to remove directories containing empty directories only. Moreover, it's quite…
maaartinus
- 4,979
- 7
- 30
- 29
212
votes
7 answers
Copy specific file type keeping the folder structure
I have a folder structure with a bunch of *.csv files scattered across the folders. Now I want to copy all *.csv files to another destination keeping the folder structure.
It works by doing:
cp --parents *.csv /target
cp --parents */*.csv"…
Mojo