I have to check the user and owner of that file which is modified in last 24 hours .I am not able to understand how could i get the file which is modified in last 24 hour
ls -lrt /dirpath | grep 'Util'
Output of this command is :
-rw-r--r-- 1 user user 186 Apr 11 08:05 Util-04-11.log.gz
-rw-r--r-- 1 user user 185 Apr 12 08:05 Util-04-12.log.gz
-rw-r--r-- 1 user user 186 Apr 13 08:05 Util-04-13.log.gz
-rw-r--r-- 1 user user 186 Apr 14 08:05 Util-04-14.log.gz
-rw-r--r-- 1 user user 278 Apr 20 08:05 Util-04-20.log
Now i want to check user and owner of file which is modified in last 24 hours.How we can do this in unix.
You can use find to filter files with corresponding modified date.
From the man page:
find $HOME -mtime 0
Search for files in your home directory which have been modified in
the last twenty-four hours. This command works this way because the
time since each file was last modified is divided by 24 hours and
any remainder is discarded. That means that to match -mtime 0, a
file will have to have a modification in the past which is less
than 24 hours ago.
With that in mind you can use the -exec option to build the following command
find /dirpath -mtime 0 -exec stat -c "%n %U %G" '{}' \;
You could use the find command specifying creation time is less than one day (-ctime 0), then use xargs to perform your ls:
find /dirpath -name "*Util*" -ctime 0 -type f |xargs ls -lrt
Hope it helps.
Related
I connect to a remote computer thru VNC and use Konsole for my work. Konsole is version 2.3.3 using KDE 4.3.4. I have these two aliases:
alias ll 'ls -haltr; pwd'
alias cd 'cd \!*; ll'
which I observed to have the following behavior:
When path exists, it will cd to it and also do the ll alias
When path doesn't exist, it will simply say the path doesn't exist and won't do the ll anymore
Example:
Path exists
[10] % cd foo
total 14K
-rw-r----- 1 user group 913 Jun 3 2014 readme
-rw-r----- 1 user group 1.2K Dec 3 2020 report.txt
drwxr-x--- 2 user group 4.0K Jan 12 17:50 ./
drwx------ 77 user group 8.0K Jun 24 11:57 ../
/home/user/foo
[11] %
Path doesn't exist
[10] % cd nowhere
nowhere: No such file or directory.
[11] %
Now our department has transferred to another division and we've just started to connect remotely thru Exceed TurboX. I still use Konsole but the version is now 2.10.5 using KDE 4.10.5. I copied over the same two aliases, but I'm now observing a different behavior:
When path exists, it will cd to it and also do the ll alias (basically same as #1 above)
When path doesn't exist, it will attempt to cd AND still do the ll (different as #2 above)
So for #2, here's how it looks like:
[10] % cd nowhere
nowhere: No such file or directory.
total 120K
-rw-r----- 1 user group 272 Jan 6 2021 .cshrc
-rw-r----- 1 user group 1.2K Jan 6 2021 .alias
drwxr-x--- 2 user group 4.0K Jan 12 17:50 ./
drwx------ 77 user group 8.0K Jun 24 11:57 ../
/home/user
[11] %
I would like to know how to get behavior #2 of the previous working environment to this current working environment.
I've added the information on the Konsole and KDE versions because if the behavior is due to the version and there's no workaround, then I'll just be sad for the rest of my life working in this new remote desktop env. ^_^
I'm currently exploring a "check first if the path exists before doing ll" but to no avail. :'(
Edit:
The shell I'm using is tcsh
% printenv SHELL in both environments showed /bin/tcsh
And in addition:
Old environment
% echo $version
tcsh 6.17.00 (Astron) 2009-07-10 (x86_64-unknown-linux) options wide,nls,dl,al,kan,sm,rh,color,filec
New environment
% echo $version
3
The information in the question is still not sufficient to find out why tcsh behaves differently in the two working environments.
The alias defines a sequence of commands (cd followed by ll) without any condition.
alias cd 'cd \!*; ll'
On one system the execution of the alias seems to stop if the cd command reports an error for currently unknown reasons.
The correct way to prevent the execution of ll after a failed cd command would be the conditional execution of the ll command, e.g.
alias cd 'cd \!* && ll'
The decade long advice is: do not use aliases, use functions.
ll() { ls -haltr "$#" && pwd; }
cd() { cd "$#" && ll; }
I am trying to delete the following files from a directory of my unix machine:
$ ls -la
total 160
... other files ...
-rw-r--r--# 1 username staff 171 Oct 24 2017 ~$checklist.xlsx
-rw-r--r--# 1 username staff 171 Oct 16 2017 ~$papers.xlsx
-rw-r--r--# 1 username staff 162 Sep 4 2017 ~$rec.docx
-rw-r--r--# 1 username staff 162 Nov 25 21:00 ~$file1.docx
-rw-r--r--# 1 username staff 162 Nov 25 21:01 ~$file2.docx
However, when I attempt to delete them, it won't let me for various reasons. For example:
$ rm ~$checklist.xlsx
rm: ~.xlsx: No such file or directory
$ rm $checklist.xlsx
rm: .xlsx: No such file or directory
$ rm checklist.xlsx
rm: checklist.xlsx: No such file or directory
Why won't my computer let me delete these files? How can I go about deleting them? Thanks!
you need to scape those characters
a simple way to create one:
echo "fileteste" > \~\$file
a simple way to delete one:
rm \~\$file
I am trying to figure out in what condition would two different cd commands lead to the same directory.
For example: Under what condition do both cd /b/c/d/e and cd d/e change to the same directory?
Could someone help me with this as I do not quite understand how to figure this out.
If you create a symbolic link to directory "d" in the directory below b:
e.g.
/temp/b/c/d/e is the directory structure
cd /temp
ln -s /temp/b/c/d
now inside of temp you will have two directories, one real and one a symbolic link to d.
/temp$ ls -al
total 12
drwxrwxr-x 3 temp temp 4096 Oct 5 18:25 .
drwxr-xr-x 34 temp temp 4096 Oct 5 18:24 ..
drwxrwxr-x 3 temp temp 4096 Oct 5 18:24 b
lrwxrwxrwx 1 temp temp 20 Oct 5 18:25 d -> /temp/b/c/d
and you can do
cd b/c/d/e
or
cd d/e
and get to the same directory.
Say you are at the pwd (present working directory) of /b/c
Then cd /b/c/d/e will bring you to the same location as cd d/e
In the first you are defining the absolute path, whereas in the second you are defining the relative path.
Let's see the examples:
cd b/c/d/e
cd d/e
Both of them are using relative paths to e/
In fact, we can assume that in the seconds one, you are in the directory c
When I say relative path, it's because you don't have a / at the beggining of the path, and it means that cd will look for the path you're providing, from your current directory (. or $PWD).
cd ./b/c/d/e
cd ./d/e
or
cd "$PWD"/b/c/d/e
cd "$PWD"/d/e
You can get your current directory with the pwd command. It will give you the value of the PWD environment variable
I have 4 files: the naming convention is as follows:
hello.account.sub1.001
hello.account.sub2.001
hello.account.sub3.001
hello.account.sub4.001
If I use ls -l hello.account*001 to search files, no problem exists.
However, problem exists when using ls -l hello.account.*.001
The system complains that No such file or directory
I assume the system considers hello.account.*.001 is a single file.
This interests me so I ask: how can you search the file if a full stop is specified as searching criteria?
Many Thanks
Filename globbing is done by the shell, before actually executing the command (such as ls in your case). The following works:
$ ksh --version
version sh (AT&T Research) 93t+ 2010-06-21
$ ls -l hello.account.*.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub1.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub2.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub3.001
-rw-r--r-- 1 andreas users 0 Jul 22 03:59 hello.account.sub4.001
while the following does not:
$ ls -l "hello.account.*.001"
ls: hello.account.*.001: No such file or directory
The reason is that in the first case, the shell expands the file name pattern before executing ls - ls will then see four different file names passed as arguments.
In the second case, since the file name pattern is escaped with double quotes, ls gets the pattern itself passed (which ls does not further expand - it looks for a file with the name hello.account.*.001)
Can someone please help me with this:
As seen below I have a file and directory with the same name as "sp"
How do I delete the file "sp" the one with 44673Bytes size
opxnyd#opxzone1d:/opt/opxnyd/packages/OPXPNY3DB/src/OPXPNYP>ls -alrt
-rwxr-xr-x 1 opxnyd opics 44673 Sep 7 2011 sp
drwxr-xr-x 4 opxnyd opics 1974 May 10 10:22 sp
The trick is that they don't actually have the same name. one of them has a blank or non-printing character in the name. Try ls --escape to see.
Like Charlie Martin said, they dont actually have the same name. But you could do a rm sp* without -r option (directory), deleting only the file.
Try renaming the file (any of them, then) delete the one you don't want (and rename again, if you happed to rename the folder)
You cannot have a directory and file with the same name. One of them would be probably having a white-space or some other non printable character in it.
Take this example:
$ touch "sp"
$ mkdir "sp "
$ ls -lrt
total 2
-rw-r--r-- 1 user staff 0 May 18 15:47 sp
drwxr-xr-x 2 user staff 68 May 18 15:47 sp
To delete just the file you can use following find command:
find -E . -depth 1 -type f -regex "\./sp[ \t]*" -exec rm {} \;
OR following rm command:
\rm -i sp\ *