Linked Questions

-2
votes
1answer
3k views

wc -c not working in a loop in the script [duplicate]

So I'm writing a simple script that checks if the size of the file is less than the given argument and if its true then its suppose to echo "YES" #!bin/bash Function () { cd $1 lista=`ls` ...
1
vote
2answers
664 views

Dealing with spaces of variables for `mv` [duplicate]

let's say I have a directory with the following files/directories: google apple mozilla foundation # a file with spaces browsers So I would like to move files into browsers directory. Here is a ...
0
votes
0answers
131 views

What is wrong with parsing the ls command ? [duplicate]

I have been told that it is unwise to parse the output of LS due to security precautions. The adage used was "parse sparsely and dont eat parsley" I was attempting to count the amount of files ...
1
vote
1answer
36 views

Use the shell test to validate basic file information. [duplicate]

I am trying to write a Bash script that takes the name of a file or directory as an argument and reports if the file is a directory, regular file or other. The script should also report if the user ...
411
votes
4answers
933k views

How do I make `ls` show file sizes in megabytes?

What commands do I need for Linux's ls to show the file size in MB?
128
votes
14answers
92k views

How can I grep in PDF files?

Is there a way to search pdf files using the power of grep, without converting to text first in Ubuntu?
166
votes
6answers
18k views

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 ...
122
votes
8answers
260k views

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 . ...
77
votes
9answers
196k views

How to output only file names (with spaces) in ls -Al?

I should echo only names of files or directories with this construction: ls -Al | while read string do ... done ls -Al output : drwxr-xr-x 12 s162103 studs 12 march 28 12:49 personal ...
72
votes
6answers
102k views

In linux, how to delete all files EXCEPT the pattern *.txt?

I know how to delete all txt file under current directory by rm *.txt. Does anyone know how to delete all files in current directory EXCEPT txt file?
41
votes
10answers
63k views

Show only hidden files (dot files) in ls alias

I'm using the command ls -a | grep '^\.' for showing only the hidden files. I added the line alias hidden='ls -a | grep '^\.'' # show only hidden files to .bash_aliases file but this does not ...
20
votes
15answers
40k views

'ls -1' : how to list filenames without extension

ls -1 lists my elements like so: foo.png bar.png foobar.png ... I want it listed without the .png like so: foo bar foobar ... (the dir only contains .png files) Can somebody tell me how to use ...
54
votes
6answers
102k views

How to copy some, but not all files?

So, you can use the * as a wild card for all files when using cp within context of a directory. Is there a way to copy all files except x file?
57
votes
7answers
71k views

How to match case insensitive patterns with ls?

I would like to list all files matching a certain pattern while ignoring the case. For example, I run the following commands: ls *abc* I want to see all the files that have "abc" as a part of the ...
29
votes
6answers
75k views

How do I pipe ls to grep, and delete the files filtered by grep?

I wanted to delete some package in my home file, but the filename was too long (google-chrome-stable_current_i386.deb). So, I decided to use the command ls|grep chrome|rm to pipe the files to grep to ...

15 30 50 per page