Dear experts,
I am a relative novice in the Unix and came across a very useful code that I regularly use for my research blindly. I am wondering if any of the professional members could kindly briefly explain to me what the code actually does?
Many thanks in advance
The script is
The original title is : Find duplicates in column 1 and merge their lines (awk?)
There are files on a remote server with the file name ending in "mm-dd-yy.txt". The script I am running is:
mls "Daily_Service_Text_File_*" /my/local/dir/Filelisting.txt
nawk -F_ -f file.awk /my/local/dir/Filelisting.txt | sort -k1n | cut -f2- | tail -1
It worked up too "12-31-07.txt" but... (3 Replies)
I found this very useful perl script that will check a remote ftp server, search for files of a specific time and get them. When I run the script it works, but it gave me the following error:
Couldn't get filename_12-13-07.txt Bad file number
What in this script would cause this? I know... (2 Replies)
Hi people I am trying to learn this code and see how it relates to the old DOS days. I have a line of code that I am not sure what the first part does. Any help will be greatly appreciated.
It is from a Save command that is used to backup files to a directory.
It goes like this
if ;then... (10 Replies)
Hi,
I have a script at the moment of which reads in simply what the latest version is within a folder i.e. v001, v002, v003 etc and then stores this latest version in a variable i.e. $LATEST would echo v003. I have then cut this string so that I only consider the 003 part. I would then like to... (3 Replies)
I'm reading about command substitutions and came across this little function in my book:
function lsd
{
date=$1
ls -l |grep -i "^.\{42\}$date"|cut -c55-
}
it's a little example which is supposed to select files by modification date, given as an argument to the function.
I... (3 Replies)
I am trying to simplify the coding in a script I was given, but it was written 7-10 years ago and is pretty complicated. below is a tidbit, if someone can break it down for me I would appreciate it.
sub ParseText
{
my ($line, $key, $value, $sub, $script);
foreach $line (@_)... (0 Replies)
I'm going through my bash book and came across this if statment.
if *$)" ]; then
the book says that the grep expression means "an initial dash followed by a digit" (which I understand) "optionally followed by one or more digits" That's the part I can't figure out -- I know the * is a... (8 Replies)
hello,
I would appreciate a little assistance with a process I'm trying to automate. I have several files that are zipped in central location, all follow the same naming conventions i.e (file 1, file 2, etc). what i would like to do is unzip the files and combined them into one file, basically... (2 Replies)
I have a string, eg 7f30.3 and I want to store things in the following way
npos = 7
decform = true
width = 30
ndp = 3
I need to read each character one by one. I am coding in fortran but I can try to code it should answer be given in C in the above way. (2 Replies)
Discussion started by: kristinu
2 Replies
LEARN ABOUT DEBIAN
stat::lsmode
lsMode(3pm) User Contributed Perl Documentation lsMode(3pm)NAME
Stat::lsMode - format file modes like the "ls -l" command does
SYNOPSIS
use Stat::lsMode;
$mode = (stat $file)[2];
$permissions = format_mode($mode);
# $permissions is now something like `drwxr-xr-x'
$permissions = file_mode($file); # Same as above
$permissions = format_perms(0644); # Produces just 'rw-r--r--'
$permissions = format_perms(644); # This generates a warning message:
# mode 644 is very surprising. Perhaps you meant 0644...
Stat::lsMode->novice(0); # Disable warning messages
DESCRIPTION
"Stat::lsMode" generates mode and permission strings that look like the ones generated by the Unix "ls -l" command. For example, a regular
file that is readable by everyone and writable only by its owner has the mode string "-rw-r--r--". "Stat::lsMode" will either examine the
file and produce the right mode string for you, or you can pass it the mode that you get back from Perl's "stat" call.
"format_mode"
Given a mode number (such as the third element of the list returned by "stat"), return the appopriate ten-character mode string as it would
have been generated by "ls -l". For example, consider a directory that is readable and searchable by everyone, and also writable by its
owner. Such a directory will have mode 040755. When passed this value, "format_mode" will return the string "drwxr-xr-x".
If "format_mode" is passed a permission number like 0755, it will return a nine-character string insted, with no leading character to say
what the file type is. For example, "format_mode(0755)" will return just "rwxr-xr-x", without the leading "d".
"file_mode"
Given a filename, do "lstat" on the file to determine the mode, and return the mode, formatted as above.
Novice Operation Mode
A common mistake when dealing with permission modes is to use 644 where you meant to use 0644. Every permission has a numeric
representation, but the representation only makes sense when you write the number in octal. The decimal number 644 corresponds to a
permission setting, but not the one you think. If you write it in octal you get 01204, which corresponds to the unlikely permissions
"-w----r-T", not to "rw-r--r--".
The appearance of the bizarre permission "-w----r-T" in a program is almost a sure sign that someone used 644 when they meant to use 0644.
By default, this module will detect the use of such unlikely permissions and issue a warning if you try to format them. To disable these
warnings, use
Stat::lsMode->novice(0); # disable novice mode
Stat::lsMode->novice(1); # enable novice mode again
The surprising permissions that are diagnosed by this mode are:
111 => --xr-xrwx
400 => rw--w----
440 => rw-rwx---
444 => rw-rwxr--
551 => ---r--rwt
600 => --x-wx--T
640 => -w------T
644 => -w----r-T
660 => -w--w-r-T
664 => -w--wx--T
666 => -w--wx-wT
700 => -w-rwxr-T
711 => -wx---rwt
750 => -wxr-xrwT
751 => -wxr-xrwt
751 => -wxr-xrwt
755 => -wxrw--wt
770 => r------wT
771 => r------wt
775 => r-----rwt
777 => r----x--t
Of these, only 400 is remotely plausible.
BUGS
As far as I know, the precise definition of the mode bits is portable between varieties of Unix. The module should, however, examine
"stat.h" or use some other method to find out if there are any local variations, because Unix being Unix, someone somewhere probably does
it differently.
Maybe it "file_mode" should have an option that says that if the file is a symlink, to format the mode of the pointed to file instead of
the mode of the link itself, the way "ls -Ll" does.
SEE ALSO
o "http://www.plover.com/~mjd/perl/lsMode/".
o ls
o chmod
o stat
AUTHOR
Mark-Jason Dominus ("mjd-perl-lsmode@plover.com").
perl v5.10.1 1998-04-20 lsMode(3pm)