Tagged Questions
17
votes
3answers
2k views
Reading lines from a file with bash: for vs. while
I'm trying to read a text file and do something with each line, using a bash script.
So, I have a list that looks like this:
server1
server2
server3
server4
I thought I could loop over this using ...
11
votes
6answers
6k views
How do I can get the size of a file in a bash script?
How do I can get the size of a file in a bash script?
How do I assign this to a bash variable so I can use it later?
9
votes
6answers
309 views
How to copy every 4th file in a folder
I have a lot of files in a folder, named like 00802_Bla_Aquarium_XXXXX.jpg. Now I need to copy every 4th file to a subfolder, saying in selected/.
00802_Bla_Aquarium_00020.jpg <= this one
...
7
votes
2answers
157 views
Cleaner way to delete files on Linux which include a datestamp as part of file name
I have a new requirement to purge MySQL dump files that are older than 30 days. The files use a naming convention of "all-mysql-YYYYMMDD-HHMM.dump". The files are located on SAN mounted file system, ...
6
votes
6answers
4k views
Shell script for moving oldest files?
How do I write a script for moving just the 20 oldest files from one folder to another? Is there a way to grab the oldest files in a folder?
5
votes
4answers
2k views
Number of files containing a given string
How can I count the number of files (in a directory) containing a given string as input in bash/sh?
5
votes
5answers
174 views
Is there a way to see the permissions of all the intermediate directories of a path..?
I have a file path..
Is there any single command to see the file/directory permissions of all the intermediate directories in the path..?
5
votes
7answers
802 views
Bash, remove oldest files
I`m trying to delete old files from directory and leave only 3 newest files.
cd /home/user1/test
while [ `ls -lAR | grep ^- | wc -l` < 3 ] ; do
rm `ls -t1 /home/user/test | tail -1`
...
5
votes
1answer
754 views
Fast elimination of duplicate lines across multiple files
I have a huge amount of data in which each (data-)line should be unique.
There are a lot of files in one folder in which this is already true. It is about 15GB splitted into roughly 170 files with ...
4
votes
1answer
240 views
Renaming files from bash in linux
There is a bunch of files of the following format hh-mm-ss.png where hh, mm, ss are hour, minute and second. How can I rename all these files in the directory in a sequential way from 1.png til n.png ...
4
votes
1answer
106 views
Move a file and re-target all of its symlinks [duplicate]
Possible Duplicate:
How can I “relink” a lot of broken symlinks?
Is there any way to move a file to a new location, and then re-target its symlinks to the new location, using a shell ...
3
votes
2answers
123 views
Bash - file, arrays and output
I have a file that contains employees names, departments and the cities the employee is in, something like:
John
IT
Chicago
Joshua
accounting
New York
Marcy
CEO
Los Angeles
...
I have to transform ...
3
votes
2answers
186 views
List files created on Sundays
How do I list/find all the files created on Sundays or Mondays?
How do I use the date parameter to display them?
Something like :
ls -f date + %a
or
find -type f | date +%A
or
find -type f ...
3
votes
1answer
378 views
Replace variable read from a text file (so they can be interpreted)
I tried several stuff with not luck so maybe one of you experts can help me (I hope!).
I want to store in a text file some select statement that contain variables like a date:
$ cat res.txt
select ...
3
votes
4answers
170 views
Using GNU Parallel With Split
I'm loading a pretty gigantic file to a postgresql database. To do this I first use split in the file to get smaller files (30Gb each) and then I load each smaller file to the database using GNU ...