Most Popular
1500 questions
164
votes
12 answers
rm -rf all files and all hidden files without . & .. error
rm -rf /some/path/* deletes all non-hidden files in that dir (and subdirs).
rm -rf /some/path/.* deletes all hidden files in that dir (but not subdirs) and also gives the following error/warning:
rm: cannot remove directory: `/some/dir/.'
rm: cannot…

Jake Wilson
- 1,743
164
votes
4 answers
Trying to sort on two fields, second then first
I am trying to sort on multiple columns. The results are not as expected.
Here's my data (people.txt):
Simon Strange 62
Pete Brown 37
Mark Brown 46
Stefan Heinz 52
Tony Bedford 50
John Strange 51
Fred Bloggs 22
James Bedford 21
Emily Bedford 18
Ana…

Harry
- 1,943
164
votes
9 answers
List only regular files (but not directories) in current directory
I can use ls -ld */ to list all the directory entries in the current directory. Is there a similarly easy way to just list all the regular files in the current directory? I know I can use find
find . -maxdepth 1 -type f
or stat
stat -c "%F %n" * |…

daniel kullmann
- 9,527
- 11
- 39
- 46
164
votes
11 answers
How can I find out which users are in a group within Linux?
I've recently been creating new users and assigning them to certain groups. I was wondering if there is a command that shows all the users assigned to a certain group?
I have tried using the 'groups' command however whenever I use this it says…

Jess Louise
- 1,761
164
votes
2 answers
Do parentheses really put the command in a subshell?
From what I've read, putting a command in parentheses should run it in a subshell, similar to running a script. If this is true, how does it see the variable x if x isn't exported?
x=1
Running (echo $x) on the command line results in 1
Running…

Igorio
- 7,519
- 7
- 20
- 11
163
votes
16 answers
How to insert text before the first line of a file?
I've been looking around sed command to add text into a file in a specific line.
This works adding text after line 1:
sed '1 a\
But I want to add it before line 1. It would be:
sed '0 a\
but I get this error: invalid usage of line address 0.
Any…

Manolo
- 1,767
- 2
- 11
- 11
163
votes
13 answers
How do I remove the first 300 million lines from a 700 GB txt file on a system with 1 TB disk space?
How do I remove the first 300 million lines from a 700 GB text file
on a system with 1 TB disk space total, with 300 GB available?
(My system has 2 GB of memory.)
The answers I found use sed, tail, head:
How do I delete the first n lines of a…

Kris
- 1,283
163
votes
3 answers
What are pseudo terminals (pty/tty)?
This might be really basic question but I want to understand it thoroughly.
What is a pseudo terminal? (tty/pty)
Why do we need them? How they got introduced and what was the need for it?
Are they outdated? Do we not need them anymore? Is there…

hari
- 2,470
163
votes
2 answers
Create symlink - overwrite if one exists
I want to take down data in /path/to/data/folder/month/date/hour/minute/file and symlink it to /path/to/recent/file and do this automatically every time a file is created.
Assuming I will not know ahead of time if /path/to/recent/file exists, how…

drjrm3
- 2,055
163
votes
4 answers
How to make log-rotate change take effect
I followed this link to change log-rotate configuration for RHEL 6
After I made the change to config file, what should I do to let this take effect?

BufBills
- 3,095
162
votes
6 answers
How to merge all (text) files in a directory into one?
I've got 14 files all being parts of one text. I'd like to merge them into one. How to do that?

Ivan
- 17,708
162
votes
13 answers
How to XZ a directory with TAR using maximum compression?
So I need to compress a directory with max compression.
How can I do it with xz? I mean I will need tar too because I can't compress a directory with only xz. Is there a oneliner to produce e.g. foo.tar.xz?

LanceBaynes
- 40,135
- 97
- 255
- 351
162
votes
1 answer
How is Mono magical?
I'm learning C#, so I made a little C# program that says Hello, World!, then compiled it with mono-csc and ran it with mono:
$ mono-csc Hello.cs
$ mono Hello.exe
Hello, World!
I noticed that when I hit TAB in bash, Hello.exe was marked executable.…

cat
- 3,468
- 4
- 23
- 51
162
votes
2 answers
SSH Key Permissions chmod settings?
I need to use SSH on my machine to access my website and its databases (setting up a symbolic link- but I digress).
Following problem
I enter the command:
ssh-keygen -t dsa
To generate public/private dsa key pair. I save it in the default…

crissixpaul
- 1,721
162
votes
9 answers
Run a command without making me wait
On the CLI, sometimes a command I type takes a while to complete, and sometimes I know when that's about to happen. I'm a bit confused on "backgrounding" and such in Linux.
What is the most common (or user-friendly way) of telling the CLI that I…

themirror
- 6,988