Space Issue in Linux [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
How to identify/ address the space issue in Linux. When I put
df -h
I get details of space availability of mounted devices. When i check the drive allocated for me is almost full.
Filesystem Size Used Avail Use% Mounted
/dev/mapper/rootvg-home 248M 236M 0 100% /home
You can see usage 100% and availability is 0 . How do I find any unwanted files in /home. I do lot of grep,sed,awk. Due to sed some temp files created but those are zero bytes. Apart from this any other way to identify the space, so that I can free some space !!!!
Thanks in advance. If i dont make sense, put a comment. i will address ASAP.

Finds all files over 20,000KB (roughly 20MB) in size and presents their names and size in a human readable format:
find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

You can do
du -sh *
for human readable file size or
du -s * | sort -n
for size-sorted file size
And recursively check big directories for unwanted files

Related

What do terminal commands ls > wc and ls | wc show? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I know what the commands ls and wc do, but I can not find out what ls > wc and ls | wc will show. Can someone please help me flush out the meaning of this commands?
ls | wc The output from the ls command is piped into the wc command. So it will count the words which are in the output of ls. So you see simply the number of files read by ls.
ls > wc This creates a new file in your current working directory with the name wc with the output of your ls command. The program wc is not used here, simply a new file with the same name is created. You can simply look into this new file with your favorite editor or simply use cat for it.

how to get the total size of certain folders in bash? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
How can I get the total size of the certain folders?
For example I have a list of specific folder names in users.txt
# cat users.txt
user1
user2
user3
all this folders are locate in /home/
I have tried to execute:
# for i in `cat users.txt`; do du -shc /home/$i/; done
3.9M /home/user1/
3.9M total
141M /home/user2/
141M total
75M /home/user3/
75M total
but I need a total size of all of this folders.
du -shc $(sed 's#^#/home/#' users.txt)
That uses the contents of users.txt, prepended with /home/, as the arguments to du, so it will sum them for you.
You can pass output of du to tail -n 1 or execute
du -s directory
To get only size you can do
du -s directory | cut -f1

Why `ls` list multiple files per line, but `ls pipe/redirect` list just 1 file per line? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Just curious, this is normal-expected behavior of ls:
user#host:~$ ls
Codes Documents Music Pictures Templates
Desktop Downloads Papers Public Videos
But when I use ls with pipe/redirection, it behave like ls -1:
user#host:~$ ls | cat
Codes
Desktop
Documents
Downloads
Music
Papers
Pictures
Public
Templates
Videos
Why? (and how to write such program that gives difference output between stdout and pipe like this?)
P.S. I also set alias l='ls -F', and this time pipe/redirection is no longer ls -1 style:
user#host:~$ l | cat
Codes/ Documents/ Music/ Pictures/ Templates/
Desktop/ Downloads/ Papers/ Public/ Videos/
Without using the alias, it does the command in ls -1 style, however:
$ ls -F | cat
Codes/
Desktop/
Documents/
Downloads/
Music/
Papers/
Pictures/
Public/
Templates/
Videos/
You can check this line from the source:
if (format == long_format)
format = (isatty (STDOUT_FILENO) ? many_per_line : one_per_line);
It uses the isatty function to check if stdout points to a tty, and to print many_per_line if it does or one_per_line if it does not.
Here is how GNU ls does it (ls.c):
if (isatty (STDOUT_FILENO))
{
format = many_per_line;
}
else
{
format = one_per_line;
}

Meaning of command ls -lt | wc -l [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
My friend just passed me this command to count the number of files in a directory:
$ ls -lt | wc -l
Can someone please help me flush out the meaning of this command? I know that ls is to list all the files. But what does -lt mean?
Also, I get a different count if I use ls | wc -l with no -lt option. Why is that the case?
You'll want to get familiar with the "man (manual) pages":
$ man ls
In this case you'll see:
-l (The lowercase letter ``ell''.) List in long format. (See below.) If
the output is to a terminal, a total sum for all the file sizes is
output on a line before the long listing.
-t Sort by time modified (most recently modified first) before sorting the
operands by lexicographical order.
Another way you can see the effect of the options is to run ls without piping to the wc command. Compare
$ ls
with
$ ls -l
and
$ ls -lt

How can I use grep to show just filenames on Linux? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 11 months ago.
The community reviewed whether to reopen this question 12 days ago and left it closed:
Original close reason(s) were not resolved
Improve this question
How can I use grep to show just file-names (no in-line matches) on Linux?
I am usually using something like:
find . -iname "*php" -exec grep -H myString {} \;
How can I just get the file-names (with paths), but without the matches? Do I have to use xargs? I didn't see a way to do this on my grep man page.
The standard option grep -l (that is a lowercase L) could do this.
From the Unix standard:
-l
(The letter ell.) Write only the names of files containing selected
lines to standard output. Pathnames are written once per file searched.
If the standard input is searched, a pathname of (standard input) will
be written, in the POSIX locale. In other locales, standard input may be
replaced by something more appropriate in those locales.
You also do not need -H in this case.
From the grep(1) man page:
-l, --files-with-matches
Suppress normal output; instead print the name of each input
file from which output would normally have been printed. The
scanning will stop on the first match. (-l is specified by
POSIX.)
For a simple file search, you could use grep's -l and -r options:
grep -rl "mystring"
All the search is done by grep. Of course, if you need to select files on some other parameter, find is the correct solution:
find . -iname "*.php" -execdir grep -l "mystring" {} +
The execdir option builds each grep command per each directory, and concatenates filenames into only one command (+).

Resources