Tagged Questions
3
votes
1answer
29 views
The reverse of `tree` - reconstruct file and directory structure from text file contents?
We all know we can use tree to get a nicely formatted text "visualization" of the structure of a directory; say:
$ tree -spugD /usr/include/boost/accumulators/numeric/
...
3
votes
3answers
2k views
Check whether files in a file list exist in a certain directory
The runtime arguments are as follows: $1 is the path to the file containing the list of files
$2 is the path to the directory containing the files
What I want to do is check that each file listed in ...
3
votes
2answers
55 views
Error when calling mv with wildcards
#! /bin/bash
error_text=$(tail -n +1 /path/dir/folder/exc/a/update/Abd/ER/* | \
grep 'Warning\|Loaded\|Event')
echo $error_text
nc 10.10.99.45 25 << EOF
ehlo mail.abc.pvt
mail from: ...
0
votes
2answers
94 views
Linux - Delete last two files automatically
In Linux, one folder is created every morning and 5 files are created in that folder.
At the end of the day (Midnight), the last two files in that folder have to be deleted. How can I accomplish ...
3
votes
5answers
112 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 ...
3
votes
3answers
147 views
Shell script to replace string in multiple files within selected directories
I created the script below which takes the path of a single directory and replaces search string in all the files within that directory. I would like to enhance this script in such a way that it can ...
2
votes
4answers
72 views
Wrapper command that runs program in temporary directory and deletes it after execution [duplicate]
I want to write a command that:
takes another command as its arguments
does a 'cd' to a temporary folder
executes the command passed in the arguments
removes the temporary folder afterwards
...
8
votes
3answers
12k views
File extensions for unix shell scripts
On wikipedia, the article for .sh says:
For the .sh file extension type, see Bourne shell.
How about other unix shells?
I know that the shebang is used inside the file to indicate an ...
2
votes
5answers
264 views
Delete all files in directories except those whose path are listed in a file
Given the following files:
data/A/a.txt
data/B/b.pdf
...
date/P/whatever.log
...
data/Z/z.jpg
I would like to delete all files in the data/A/, data/B/, ..., data/Z/ directories except those files ...
1
vote
4answers
388 views
Bash Script to Sort Files into Alphabetical Folders on ReadyNAS Duo v1
I have an old ReadyNAS Duo v1 (Sparc) running an unknown flavour of Linux.
I have a folder structure with 1,000+ files I want to move into a folder structure based on the first letter of the file ...
2
votes
1answer
1k views
Create sub-directories and organize files by date
I have some directories of files copied from my security camera that I would like to organize into sub-directories by file date. So for example;
-rwxrwxrwx 0 root root 4935241 Jul 19 2012 ...
1
vote
2answers
302 views
How do I trigger a script when a folder is updated in Solaris 5.10?
We are trying to write a script to move away files as soon as they drop in a folder. One way of achieving this is running rsync in a script on cron scheduler.
The problem with this approach is the ...
5
votes
4answers
145 views
Clean way to temporarily replace a config file?
I use a drawing program called Inkscape, which has both a GUI and a command line interface. When used on the command line, it has a large number of options that can only be controlled through a ...
2
votes
1answer
107 views
tar and if-statement
I have a script that check if a file exist inside a tar file but something's wrong because it always go to the else part of the script. I am pretty sure that it shouldn't be that way.
The date is in ...
5
votes
3answers
463 views
Maintain (or restore) file permissions when replacing file
I have a command that accepts a file as an argument, modifies the file, then writes it to the file name specified in the second argument. I'll call that program modifyfile.
I wanted it to work "in ...
0
votes
2answers
99 views
Merging multiple lines selectively?
I have a large file in which a header line is followed by a string of characters at multiple times. eg:
file1
VHBFBJBDSBVVFJBSV
SVJBVHJBVJ
SVKJBVJBNVKVJV
file2
dfhgdgffdghgg
SVKJBVJBNVKVJV
I ...
2
votes
3answers
585 views
Replace filename with parent folder name
I have a bunch of files each in their own subdirectory. I need to write a script to rename each file to have the same name as its directory: For example, given:
./1111/1234.pdf
./2222/2345.pdf
...
20
votes
1answer
568 views
How to move a directory, file by file? (instead of “copy then remove”)
My computer has one 500GB drive.
I want to move 400GB of data from /unencrypted to /encrypted.
Both directories are on the same partition, but /encrypted is handled by ecryptfs, so mv /uncrypted/* ...
20
votes
1answer
816 views
How to implement a horizontal cat? [duplicate]
Standard cat concatenates files line by line (row by row, if you will). I find myself needing a horizontal cat command more and more often recently; i.e. a command that takes a list of files and ...
1
vote
1answer
188 views
TeXstudio: open file at line number n
I am creating a script to produce some .tex files with a lot of lines (a kind of automatic sample).
The script finishes with texstudio /home/$USER/foo.tex where foo.tex is the file created before.
...
4
votes
1answer
89 views
Transform directory structure
I have the following folder structure
root folder
|-al2
|- GER.zip
|- ENG.zip
|-ww
|- GER.zip
|- ENG.zip
and so on. The folder names are random strings.
I want to sort the files in ...
0
votes
2answers
1k views
How to calculate in linux number of file inside nested directories?
I need to extract information how much files are in some directory tree:
/.../testRoot/test1/test11/..../file1
/.../testRoot/test1/test11/file2
/.../testRoot/test1/test11/..../file3
...
2
votes
3answers
3k views
How to delete the oldest directory in a given directory? [duplicate]
Possible Duplicate:
Shell script for moving oldest files?
I have a backup directory that stores x other directories that require backuping.
I need something that will run before another ...
2
votes
2answers
391 views
Comparing files and their properties
I get information of a certain set of files in my mail every day, which looks like this:
58623208 Sep 14 20:08 blbn_blfbe_drv
57904920 Sep 14 19:54 blbn_cycmn
55814208 Sep 14 06:02 clsa_Upd
38912000 ...