3
votes
2answers
85 views

exit a script if an ls line did not find any match

I am writing this script that have this line: ls -lrt /dir1/dir2/filename*.txt | tail -1 | awk '{print $9}' | read variable What I wanted is to exit the script (without using if-statement) if it ...
2
votes
3answers
108 views

Strange formatting of date in bash script

I am working on a script to sort my downloads folder by the date the files were created. This is the script I am using: #!/bin/bash cd ~/Downloads for FILENAME in * do if [[ -f $FILENAME ]]; ...
1
vote
3answers
512 views

Difference between ls -l and ll?

I'm relatively new to programming as a whole and some tutorials have been telling me to use ls -l to look at files in a directory and others have been saying ll. I know that ls is a short list, but ...
3
votes
5answers
131 views

Look if a folder has some files of certain extention

Lets say I have a file structure: $ cd /home/Desktop $ ls -d */ Abc/ Qwe/ Zxc/ Rty/ $ Now I want to iterate through every directory and look if they have any .pdf files. Could some one please ...
5
votes
2answers
279 views

Why doesn't my loop over the output of ls work?

I am trying to feed Directory names into a for loop. My code is as follows: td='/Test/TopDir/' cd "$td" for x in $(ls -d */ | cut -f1 -d'/'); do echo x=$x done The top directory I run this on ...
0
votes
2answers
134 views

Bash: iterate with variable on the lines of `ls -1` output

In a simple cycle like the following for f in $(ls -1) ; do something done I would like to store each line of the output of ls -1 in the variable f. Is there a way to do this ...
0
votes
2answers
441 views

Using `ls` recursively without -R

I am trying write a shell script that has output similar to ls -R without using the option -R. This is part of a programming assignment that forbids me from using -R, find and du. I need to identify ...
2
votes
2answers
191 views

Directories are listed twice

I have something odd. I creates some directories using a very simple script : ... create all directories ( running under a user that has the correct rights ) e.g : mkdir -p ...
3
votes
1answer
296 views

ls gives me different sort orders during a cron job

I have a cron job that, among other things, does a recursive ls of a directory into a file. This gets compared to another file that I've created that, supposedly, contains an identical listing of the ...
4
votes
4answers
356 views

linux + how to ignore (filter) file with space

Sometimes a file name is created from a couple of names and space between each name as the following: $ touch "A B C" $ ls A B C <-- one file but has three words ! ...
6
votes
6answers
10k views

Show sum of file sizes in directory listing

The Windows dir directory listing command has a line at the end showing the total amount of space taken up by the files listed. For example, dir *.exe shows all the .exe files in the current ...
1
vote
2answers
549 views

Ignore all matches to negated extglob pattern in recursive ls

I would like to recursively list all files in a directory which match a given input pattern using ls. (Oh, and this is in Bash). The only way I can think of to do this using ls is to shopt -s extglob ...
3
votes
2answers
5k views

list all files newer than given timestamp and sort them

I want to list all files (sorted by date) that are newer than timestamp in format 20130207003851 in directory /tmp only. Subdirectories can be omitted. Using SUSE Linux Enterprise Server 11. The ...
0
votes
1answer
384 views

difficalty to save traceroute output in shell variable?

I need to filter and store traceroute output in shell variable (array). But I am getting some unusual output. As I try to explain in following lines. My present directory is temp, having some ...
1
vote
2answers
322 views

List info about files/directories with spaces

I am trying to use ls to get information about files and directories. My current command fails to properly get the name whenever a file/directory has a space. I am using this to list all ...
3
votes
2answers
1k views

How to solve sudo: unable to execute /bin/ls: Argument list too long

When I run this command from php sudo -u db2inst1 ls -t /var/lib/edumate/bdrs/*/*/daily/*NODE* | sort -r I receive sudo: unable to execute /bin/ls: Argument list too long ls lists all daily backup ...
2
votes
1answer
4k views

How to get exact file size and file name?

Right now I am using ls -lt /my/directory (see below) then php parses the output. But inconsistently because the delimiter is space and there might be two or more spaces in between two fields. The ...
2
votes
3answers
582 views

Can I list only specific subdirectories?

I have a folder tree structure like arndell \_databases \_daily \_weekly claremont \_databases \_daily \_weekly monte \_databases \_daily \_weekly and I am only after all files inside ...
3
votes
3answers
3k views

How to search and replace text in all php-files in a directory and it's subdirectories

I am looking for a shell script that recursively traverses all .php files in a directory and performs a search & replace of a particular text pattern. The search pattern is quite long ( > 5000 ...
-2
votes
1answer
248 views

Why does this script show all files in the directory and not just PDF files?

I wrote the script below to find the number of PDF files in a given directory. However, it instead shows all the files in the directory: #!bin/bash message="." message1="*.pdf" ls -al $message ...
13
votes
3answers
460 views

When does `ls -s` print “0”

Of course, the standard way of testing if a file is empty is with test -s FILE, but one of our clients have received a script containing tests like this: RETVAL=`ls -s ./log/cr_trig.log | awk '{print ...
5
votes
2answers
1k views

How to list files and directories with directories first

I have two questions. First, which command lists files and directories, but lists directories first? Second question: I want to copy a list of files into a single directory, but make the target ...
5
votes
6answers
3k views

Compare files that are in directory 1 but not directory 2?

I'm having trouble with a bash script I want to make I know ls will list files that are in a directory but I want it to list directories that are in directory1 but NOT in directory2, and then list ...
15
votes
3answers
13k views

Find the owner of a directory or file, but only return that and nothing else

I am looking for a command that will return the owner of a directory and only that--such as a regex parsing the ls -lat command or something similar? I want to use the result in another script.