Most Popular

1500 questions
296
votes
2 answers

How to write startup script for Systemd?

I have 2 graphics cards on my laptop. One is IGP and another discrete. I've written a shell script to to turn off the discrete graphics card. How can I convert it to systemd script to run it at start-up?
Sharique
  • 3,183
294
votes
7 answers

How to go to the previous working directory in terminal?

In terminal, how can I define a key to go to the previous directory which I was in when changing directory with the cd command? For example, I'm in /opt/soft/bin and I cd into /etc/squid3 and I want to get back to the first directory.
Hojat Taheri
  • 5,056
293
votes
9 answers

How can I display the contents of a text file on the command line?

I would like to display the contents of a text file on the command line. The file only contains 5-6 characters. Is there an easy way to do this?
Sam Weinberg
  • 3,043
293
votes
10 answers

How to know if a disk is an SSD or an HDD

I want to know whether a disk is a solid-state drive or hard disk. lshw is not installed. I do yum install lshw and it says there is no package named lshw. I do not know which version of http://pkgs.repoforge.org/lshw/ is suitable for my CentOS. I…
user4951
  • 10,519
293
votes
2 answers

Recursively delete all files with a given extension

I want to delete all *.o files in a directory and its sub-directories. However, I get an error: sashoalm@aspire:~/.Workspace.OLD$ rm -r *.o rm: cannot remove `*.o': No such file or directory On the other hand, rm *.o works, but it's not recursive.
sashoalm
  • 5,820
292
votes
29 answers

SSH tunneling error: "channel 1: open failed: administratively prohibited: open failed"

When I open this ssh tunnel: ssh -nXNT -p 22 localhost -L 0.0.0.0:8984:remote:8983 I get this error when trying to access the HTTP server running on localhost:8984: channel 1: open failed: administratively prohibited: open failed What does this…
Neil
  • 3,462
290
votes
6 answers

What's the difference between $(stuff) and `stuff`?

There are two syntaxes for command substitution: with dollar-parentheses and with backticks. 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?
tshepang
  • 65,642
289
votes
8 answers

How to determine where an environment variable came from?

I have a Linux instance that I set up some time ago. When I fire it up and log in as root there are some environment variables that I set up but I can't remember or find where they came from. I've checked ~/.bash_profile, /etc/.bash_rc, and all…
Joel
  • 2,993
289
votes
12 answers

How do I convert an epoch timestamp to a human readable format on the cli?

How do I convert an epoch timestamp to a human readable format on the cli? I think there's a way to do it with date but the syntax eludes me (other ways welcome).
xenoterracide
  • 59,188
  • 74
  • 187
  • 252
288
votes
2 answers

how can I recursively delete empty directories in my home directory?

Possible Duplicate: How to remove all empty directories in a subtree? I create directories very often, scattered over my home directory, and I find it very hard to locate and delete them. I want any alias/function/script to find/locate and delete…
287
votes
3 answers

Most efficient method to empty the contents of a file

I am aware of three methods to delete all entries from a file. They are >filename touch filename1 filename < /dev/null Of these three I abuse >filename the most as that requires the least number of keystrokes. However, I would like to know which…
debal
  • 3,704
286
votes
16 answers

How do I find out what hard disks are in the system?

I need to know what hard disks are available, including ones that aren't mounted and possibly aren't formatted. I can't find them in dmesg or /var/log/messages (too much to scroll through). I'm hoping there's a way to use /dev or /proc to find out…
xenoterracide
  • 59,188
  • 74
  • 187
  • 252
285
votes
7 answers

Find out current working directory of a running process?

What command(s) can one use to find out the current working directory (CWD) of a running process? These would be commands you could use externally from the process.
slm
  • 369,824
285
votes
18 answers

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 /var/www 1.8M /var/tmp 1.9G /var/named 2.9M …
xenoterracide
  • 59,188
  • 74
  • 187
  • 252
285
votes
10 answers

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 output nothing. I'm most familiar with OS X and so…
cwd
  • 45,389