Most Popular

1500 questions
218
votes
7 answers

Determine if Git working directory is clean from a script

I have a script which runs rsync with a Git working directory as destination. I want the script to have different behavior depending on if the working directory is clean (no changes to commit), or not. For instance, if the output of git status is as…
218
votes
2 answers

How do I unset a variable at the command line?

I have tried the following command to set Proxy on yaourt: export ALL_PROXY=http://proxy.example.com:8080 The question is how to unset the proxy on yaourt? In general, how can I unset the value of a variable in the current shell?
217
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
  • 5,059
217
votes
8 answers

Run a command that is shadowed by an alias

Let's say I have the following alias in bash - alias ls='ls --color=auto' - and I want to call ordinary ls without options. Is the only way to do that is to unalias, do the command and then alias again? Or there is some nifty trick or workaround?
217
votes
17 answers

Any reason NOT to run Linux in a VM all the time?

I've switched to using Arch Linux for most of my day to day work and don't need Windows for anything but gaming and the couple of apps that aren't ported to Linux like OneNote. My Linux distribution is hosted in VirtualBox with Windows as host, and…
217
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,281
216
votes
4 answers

Why do we use su - and not just su?

I don't understand why su - is preferred over su to login as root.
Dharmit
  • 4,310
216
votes
4 answers

$VAR vs ${VAR} and to quote or not to quote

I can write VAR=$VAR1 VAR=${VAR1} VAR="$VAR1" VAR="${VAR1}" the end result to me all seems about the same. Why should I write one or the other? are any of these not portable/POSIX?
xenoterracide
  • 59,188
  • 74
  • 187
  • 252
216
votes
7 answers

Zip the contents of a folder without including the folder itself

I have a directory called folder that looks like this: folder -> root_folder -> some files I want to zip this directory into zipped_dir, I tried: zip -r zipped_dir.zip folder/* But this generates a ZIP that looks like…
Juicy
  • 3,875
215
votes
11 answers

How to export variables from a file?

I have a tmp.txt file containing variables to be exported, for example: a=123 b="hello world" c="one more variable" How can I export all these variables using the export command, so that they can later be used by child processes?
Neerav
  • 3,095
215
votes
7 answers

How can I wrap text at a certain column size?

I know that I can use something like cat test.txt | pr -w 80 to wrap lines to 80 characters wide, but that puts a lot of space on the top and bottom of the printed lines and it does not work right on some systems What's the best way to force a text…
cwd
  • 45,389
215
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нιη
  • 41,407
214
votes
5 answers

How do I determine the number of RAM slots in use?

I forgot how many RAM (DIMM) modules are installed on my laptop. I do not want to unscrew it but want to look it up on the console using bash. How do I gather this information?
k0pernikus
  • 15,463
214
votes
9 answers

ssh-add is not persistent between reboots

I added a ssh key to the agent by: $ ssh-add ~/.ssh/id_rsa_mac Identity added: /Users/alex/.ssh/id_rsa_mac (/Users/alex/.ssh/id_rsa_mac) After a reboot the agent doesn't have this key added anymore: $ ssh-add -l The agent has no identities. Why…
Incerteza
  • 2,671
213
votes
15 answers

How do I write a retry logic in script to keep retrying to run it upto 5 times?

I want to write logic in shell script which will retry it to run again after 15 sec upto 5 times based on "status code=FAIL" if it fails due to some issue.