Chinese 

cmd:ls show Chinese 

Show Chinese characters in file names:

ls --show-control-chars

documented on: 02-17-99 15:05:22

search Chinese 

Search Chinese with Perl, grep nok.

perl -ne "print if /[\200-\377]/"

Remove all Chinese lines:

perl -ne "next if /[\200-\377]/; print"

will 0-length file take up inodes 

Newsgroups:  gmane.linux.debian.user
Date:        Sat, 5 Mar 2005 17:09:38 -0800
> Will 0-length file take up inodes? If yes, how can I create a

All files need inodes. If you want support for tail-packing, use Reiserfs. XFS *may* support this as well, but I'm not sure. At least with Reiserfs, XFS, and JFS, you don't need to pre-allocate space for inodes, and you won't run out as long as you have free disk space.

Todd A. Jacobs

File commands 

cmd:type 

$ type bash
bash is hashed (/opt/bin/bash)

cmd:which 

$ which bash
/opt/bin/bash

cmd:file 

$ file /bin/bash
/bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked (uses shared libs), stripped

cmd:stat 

$ stat /bin/bash
  File: "/bin/bash"
  Size: 316848       Filetype: Regular File
  Mode: (0755/-rwxr-xr-x)         Uid: (    0/    root)  Gid: (    0/    root)
Device:  3,66  Inode: 16213     Links: 1
Access: Fri Oct  5 21:11:48 2001(00000.00:01:26)
Modify: Sun Feb 27 13:44:41 2000(00586.06:28:33)
Change: Fri Dec 15 23:42:05 2000(00293.20:31:09)

difference between a file change and modification 

Here's what the UNIX man page on stat has to say about the difference between a file change and a file modification:

st_mtime Time when data was last modified. Changed by the following functions: creat(), mknod(), pipe(), utime(), and write(2).

st_ctime Time when file status was last changed. Changed by the following functions: chmod(), chown(), creat(), link(2), mknod(), pipe(), unlink(2), utime(), and write().

So a modification is a change in the data, whereas a change also happens if you modify file permissions and so on.

Find files excluding a string 

Newsgroups: comp.unix.questions
> > I want to find a list of files that does not contain a given string.
> >
>
> for files in the current directory,
> in the korn shell, you can do this:
>
> |    $ for f in *
> |    > do
> |    > [[ ! -f $f || ! -r $f ]] && continue
> |    > ! grep -q string $f && print $f
> |    > done
>
> In bash, change `print' to `echo'

It's probably easier to read it as:

[[ -f $f -a -r $f ]] || continue

which means:

Unless $f is a regular file and it is readable, continue to the next item in the list.

documented on: 2001.02.12

csh parameters 

-c        Execute  the  first  argument   (which   must   be
          present).  Remaining arguments are placed in argv,
          the argument-list variable, and passed directly to
          csh.
-x        Echo.  Set the echo variable; echo commands  after
          all substitutions and just before execution.

var for 2nd csh 

host> csh -v -x -c echo $PATH
echo
echo
host> csh -v -x -c echo $path
echo
echo
host> csh -v -x -c echo $dirstack
echo
echo
host> echo $dirstack
/home/cstudent/034897s /home/cstudent/034897s/jp /home/cstudent/034897s/bin

Conclusion 

the vars (set by set command) does not get passed to the child shell. (?)

documented on: 11-11-98

cmd:chmod 

chmod go-rx .[A-z]*
chmod 644 .plan        # -rwxr--r--
chmod 755 install      # drwxr-xr-x
chmod a+x pascal2c
chmod -R g-r * .*
>chmod -R a+r *
>chmod -R g+w *
u         user's permissions
g         group's permissions
o         others' permissions
a         all permissions (user,  group,  and
          other)

documented on: Sat 11-07-98 22:39:16

Type conditional chmod 

Newsgroups: comp.unix.shell
> changed on a Solaris 7 box. All executables need one set ie 775,
> directories another (possibly the same), and regular data files another
> ie 644.

Directories are easy enough.

find /dir -type d -exec chmod 755 {} \;

For files, you could do something like

for file in `find /dir -type f`
do
    if file $file | grep "script" >/dev/null 2>&1
    then
          chmod 775 $file
    else
          chmod 644 $file
    fi
done

This is dependant on what you include in your definition of scripts. If you have perl or other such scripts, you might want to expand the grep, eg:

file $file | egrep "script|perl|python"

"Peter Sundstrom"

Type conditional chmod 

If it's just 644 vs 755, then it's easy:

chmod -R a+rX <dir>

(add read for everybody and execute for everybody only when already at elast one execute bit is set)

execute only if the file is a directory or already has execute permission for some user (X)

Casper

cmd:chmod, sticky bit 

>Can someone explain what "sticky bit" means in an ACL?

The sticky bit is set on a public directory where users have write permission. By default, if you give someone write permission they have the ability to delete any files in the directory even if they don't own them. The could also redirect output over an existing file. By setting the sticky bit on a directory, you prevent users from deleting or acidently trashing other people's files. Do an

#  ls -ld  /tmp

to see a directory where the bit is set. To set the sticky bit on a directory, use a command like

# chmod 1777 pub_directory

Dave

documented on: 07-28-99 11:29:43

chmod —> r-sr-sr-x 

> Hi, I've been looking through all kinds of docs looking for a definition of
> the 's' in a file permission.

in the case of an executable file, an s in the owner position means that the file is "setuid." that means whenever the program is executed, the process will have an effective userid of the file's owner rather than the executing user.

likewise, an s in the group position means that the file is "setgid." whenever the program is executed, the process will have an effective groupid of the file's group rather than the executing user's group.

s means something entirely different for directories. have a look at the man page for ls for more information.

> Can someone please explain what is means (system ?) and how to achieve it
> in a chmod ?
setuid: chmod 4755 filename
setgid: chmod 2755 filename

John Gordon

documented on: 2000.08.31 Thu 00:59:44

Rename file 

The aim for above is to batch rename files. Should do like this, according to the faq:

You can also convert file names into "mv" commands with 'sed', and hand the commands off to "sh" for execution. Try

ls -d *.foo | sed -e 's/.*/mv & &/' -e 's/foo$/bar/' | sh
Note This is only work for changing the extensions! and a better way to do is just:
for i in *.txt; do mv $i `basename $i .txt`.c; done

Renaming parts other than extension 

ls -1 *.htm | xargs -i echo " mv" {} > fr
ls -1 *.htm |sed "s/xxx/yyy/" | paste fr - | sh

documented on: 08-07-99

cmd:mkdir 

DESCRIPTION

Create the DIRECTORY(ies), if they do not already exist.

-m , --mode =MODE
       set permission mode (as in chmod), not rwxrwxrwx - umask
-p , --parents
       no error if existing, make parent directories as needed
--verbose
       print a message for each created directory

documented on: 07-29-99

du & df 

>The problem is also that "du" and "df" are terribly unreliable, at least
>in my experience. "du" seems to round up to the nearest 512 bytes (or
>1024 depending on the -k flag), and I wouldn't trust "df" any further
>than I can..um..throw it.

The output of "df" gives a highly reliable representation of the amount of disk space available on a filesystem. It gets its numbers straight from the horse's mouth (i.e., it directly queries the filesystem). If these numbers seem wrong to you then I suspect that you aren't understanding what is (and is not) being counted in the report.

What "du" is reporting is the actual amount of disk used by the files --- not the sum of the data contained in each file (i.e., the amount shown by a "ls -l"), but the sum of the disk blocks used by the files. This number may be higher (due to indirect blocks and blocks for tail fragments of files) or lower (due to holes) than a direct conversion of the file's size might suggest. Indeed, du does round up each file's size to the nearest block, as each file is stored in an integer number of blocks on the disk (glossing over the issue of the use of "fragments" on several filesystems).

If what you're after is the sum of the byte counts of the files in a directory tree, without any adjustments for actual disk space used, then you'll need to use some other tool than either "du" or "df". Perhaps:

(echo 'my $c=0; END {print $c, "\n"}';
exec find2perl . -eval '$c += -s $_') | perl

Ken Pizzini

documented on: 08-03-99 16:37:05

Delete the newist files 

*Tags*: cat with line numbers on

If you got a whole bunch of files created in a directory and you don't them to be there. The quickest way to delete all those newly created files is:

ls -t | cat -n # see how many of files/dirs need to be delelted, say 14
ls -t | head -14 | xargs rm -rf

documented on: 2000.04.01 Sat

mmv 

Source: 

As of 99.02.21:

ftp://ftp.kddlabs.co.jp/.7/Usenet/comp.sources.unix/volume21/mmv/part01.z ftp://ftp.kddlabs.co.jp/.7/Usenet/comp.sources.unix/volume21/mmv/part02.z

File size: 

-rw-r—r-- 1 tong other 32489 Feb 21 16:57 part01 -rw-r—r-- 1 tong other 54134 Feb 21 16:57 part02

Comment 

C file. too big, give up!

documented on: 02-21-99 17:03:54