How to delete a NULL file from Solaris Unix? - solaris

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,

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

make_path does not set mode as specified

When I call make_path (from the core File::Path module, supplying a mode, the directory that is created does not have the mode I requested:
$ perl -MFile::Path=make_path -e 'make_path("foobar", { mode=>0770 });'
$ ls -ld foobar/
drwxr-x--- 2 itk itkadm 4096 Sep 19 11:10 foobar/
I was expecting to see:
drwxrwx--- 2 itk itkadm 4096 Sep 19 11:07 foobar/
Rather than setting the permissions for the directory to 0. Try instead just using the chmod option to File::Path::make_path
perl -MFile::Path=make_path -e 'make_path("foobar", { chmod=>0770 });'
I missed this detail in the make_path documentation:
mode: The numeric permissions mode to apply to each created directory
(defaults to 0777), to be modified by the current umask.
I was not expecting this because the shell equivalent (mkdir -m 0770 -p foobar) does not consider umask.
This works as expected:
$ perl -MFile::Path=make_path -e 'umask(0); make_path("foobar", { mode=>0770 });'
$ ls -ld foobar/
drwxrwx--- 2 itk itkadm 4096 Sep 19 11:13 foobar/
Note the umask(0).
As pointed out by Evan Carroll, the version of File::Path supplued with newer perl versions (>=5.24) have a chmod option which may be a more convenient way to set the mode of created directories.

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

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

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.