Convert `ls -lR` output to format of `find` output - find

I need to convert ls -lR output to the format of find output
E.g. I have a text file, which is an output of ls -lR. The file contains:
/tmp/1:
total 0
drwxr-xr-x 3 user1 ubuntu 80 May 10 21:13 2
-rw-r--r-- 1 user1 ubuntu 0 May 10 21:13 f1
/tmp/1/2:
total 0
drwxr-xr-x 2 user1 ubuntu 60 May 10 21:13 3
-rw-r--r-- 1 user1 ubuntu 0 May 10 21:13 f2
/tmp/1/2/3:
total 0
-rw-r--r-- 1 user1 ubuntu 0 May 10 21:13 f3
I want to convert this file to the second one with different format, just like find utility uses by default:
/tmp/1
/tmp/1/f1
/tmp/1/2
/tmp/1/2/f2
/tmp/1/2/3
/tmp/1/2/3/f3
If I have the fs, which was used for generating ls-lR, I'll just run a find /tmp/1, but in my case I have no access to the original fs.
Is it possible? There must be a short perl-script for this conversion.

You can use -ls as primary (which is slightly different from ls -l) or -exec ls -l {} +. It will however never be completely the same as ls -lR since that does different groupings and prints totals.
Actually, I think find . -type d -exec ls -l {} + is the closest approximation.

Related

How do I create multiple directories within a directory that's in a directory with a single line command

so my path is from the desktop and I tried: mkdir OS\LAB1\Finance,Public,Archive,Customer
The command makes the first 3 directories but the last three get made on my desktop and not within LAB1,how do I do it with one command line?
Thank you
not a one liner, but this does the trick
$folders = #(,'Public','Archive','Customer')
New-Item -ItemType Directory C:\OS\LAB1\Finance\ -Force
foreach($folder in $folders){
New-Item -ItemType Directory C:\OS\LAB1\Finance\$folder -Force
}
The force parameter creates all the directories in one go.
I think that you want to create 4 directories under LAB1 not a single directory four deep. in Bash you can do this.
for i in $(tr ',' '\n' <<< "Finance,Public,Archive,Customer"); do mkdir "$i"; done
Result looks like this
0 drwxr-xr-x# 7 camerontownshend staff 224 16 Mar 12:28 .
0 drwxr-xr-x# 147 camerontownshend staff 4704 16 Mar 11:13 ..
0 drwxr-xr-x# 2 camerontownshend staff 64 16 Mar 12:28 Archive
0 drwxr-xr-x# 2 camerontownshend staff 64 16 Mar 12:28 Customer
0 drwxr-xr-x 2 camerontownshend staff 64 16 Mar 12:28 Finance
0 drwxr-xr-x# 2 camerontownshend staff 64 16 Mar 12:28 Public
Explanation
for i in ... -> for loop
tr ',' '\n' -> replaces commas with new lines
do mkdir "$i" done -> run whatever is inside the do/done pair. The mkdir "$i" - substitutes the iterator from the loop as a variable into the mkdir command
To create multiple folders (full paths) in one line using a list (caution: no spaces after commas):
$ mkdir -p /tmp/{test1,test2}
To verify:
$ ls /tmp/test*
/tmp/test1:
/tmp/test2:

Alias directory minus one file

I'd like to make an alias for a directory that contains many files. If I open the aliased directory, I want to view all files except for one. New files will be added to the directory over time, and I want everything to be aliased except for the one file permanently not-aliased.
Is it possible to set this up without needing to run a script every time a file in the directory changes?
E.g.: myDir contains fileA, fileB, and fileC.
I want myAliasedDir to contain fileA and fileB, but not fileC.
Can you get away with symbolic links?
Assuming your shell is bash:
$ shopt -s extglob
$ mkdir dir1 dir2
$ cd dir1
$ touch file{1..3}
$ ls -l
total 0
-rw-r--r-- 1 jackman jackman 0 Apr 1 12:40 file1
-rw-r--r-- 1 jackman jackman 0 Apr 1 12:40 file2
-rw-r--r-- 1 jackman jackman 0 Apr 1 12:40 file3
$ cd ../dir2
$ for f in ../dir1/!(file2); do ln -s "$f"; done
$ ls -l
total 8
lrwxrwxrwx 1 jackman jackman 13 Apr 1 12:41 file1 -> ../dir1/file1
lrwxrwxrwx 1 jackman jackman 13 Apr 1 12:41 file3 -> ../dir1/file3

Open File keeps growing despite emptied content

How can I pipe a text stream into a file and, while the file is still in use, wipe it for job rotation?
Long version:
I've been struggling for a while onto an apparently minor issue, that's making my experiments impossible to continue.
I have a software collecting data continuously from external hardware (radiotelescope project) and storing in a csv format. Being the installation at a remote location I would, once a day, copy the saved data in a secure place and wipe the file content while, for the same reason, I can NOT to stop the hardware/software, thus software such as log rotation wouldn't be an option.
For as much effort spent see my previous post, it seems the wiped file keeps growing although empty.
Bizarre behavior, showing file size, truncate file, show file size again:
pi#tower /media/data $ ls -la radio.csv ;ls -s radio.csv;truncate radio.csv -s 1; ls -la radio.csv ;ls -s radio.csv
-rw-r--r-- 1 pi pi 994277 Jan 18 21:32 radio.csv
252 radio.csv
-rw-r--r-- 1 pi pi 1 Jan 18 21:32 radio.csv
0 radio.csv
Then, as soon as more data comes in:
pi#tower /media/data $ ls -la radio.csv ;ls -s radio.csv
-rw-r--r-- 1 pi pi 1011130 Jan 18 21:32 radio.csv
24 radio.csv
I thought to pipe the output into a sed command and save right away, with no luck altogether. Also, filesystem/hardware doesn't seems buggy (tried different hardware/distro/filesystem).
Would anyone be so nice to give me a hint how to proceed?
Thank you in advance.
Piped into tee with -a option. The file was kept open by originating source.
Option APPEND of tee helped to stick at the EOF new data; in the given issue, appending to the beginning when file zeroed.
For search engine and future reference:
sudo rtl_power -f 88M:108M:10k -g 1 - | tee -a radio.csv -
Now emptying the file with
echo -n > radio.csv
gets the file zeroed as expected.

Need to remove files with spaces in Debian

I need to find and remove files with spaces in them in a certain folder.
$ ls -l
total 16
-rw-r--r-- 1 smw staff 10 Feb 6 16:10 Foo Bar
-rw-r--r-- 1 smw staff 11 Feb 6 16:10 foobar
$ ls -l *\ *
-rw-r--r-- 1 smw staff 10 Feb 6 16:10 Foo Bar
$ rm -i *\ *
remove Foo Bar? y
$ ls -l
total 16
-rw-r--r-- 1 smw staff 11 Feb 6 16:10 foobar
You'll have to deal with bash's niceties when dealing with spaces...
First, you need to iterate over the files, in a way that gives you the files properly regardless of spaces. Check out this question. I'd favor this:
find ... | while read line ; do command "$line" ; done
And then it's a matter of using something like sed to change $line into whatever you need (such as the same thing without spaces) right where command "$line" is.
This is how I removed a file with a space
pi#raspberrypi ~/Music $ ls -l
-rw-r--r-- 1 pi pi 0 Feb 25 16:05 Sleep Away.mp3
pi#raspberrypi ~/Music $ rm Sleep\ Away.mp3
use the "\" forward slash to escape any spaces

How to delete a NULL file from Solaris Unix?

I have a NULL file in a directory:
-rw-r--r-- 1 blah1 blah2 83532 Nov 5 09:34 <can't see, but null here>
How do I remove this? This is very annoying as it interferes with svn status.
Thanks for any help.
Delete interactively, saying no to all of the non-null files.
/bin/rm -i *
You can remove using the iNode value (using the -i option on ls command)
# ls -li
total 16
30475938 -rw-r--r-- 1 root root 7 mar 19 10:29 -h
# find . -inum 30475938 -print
./-h
# find . -inum 30475938 -exec rm {} \;
# ls -li
total 0
In my blog, you have some examples -in Spanish- how to remove files with reserved characters.
http://sparcki.blogspot.com.es/2010/03/como-eliminar-archivos-utilizando-su.html
Urko,