Is there any way to see all the owners from current directory and file name in huge concurrent logs (without ls) - linux

For my current issue I require listing all the files which have a different owner than the current owner. We have almost 600 000 files in current directory and ls -l or any other ls command will give us trouble.
[system#support forms]$ pwd
/u01/system/reports/foms
[system#support forms]$ ls -ltr|more
total 22066
-rwxrwxrwx 1 system sys 94208 Feb 5 2016 UTIL_COGS.rdf
-rwxrwxrwx 1 system sys 417792 Feb 5 2016 UTIL_AL.rdf
-rwxrwxrwx 1 system sys 212992 Feb 10 2016 UTIL_PE_BATCH.rdf
-rwxrwxrwx 1 system sys 311296 Feb 10 2016 UTIL_GF.rdf
-rwxrwxrwx 1 dev dev 307200 Feb 10 2016 UTIL_NO_ACCT.rdf >>>> this is my Issue
-rwxrwxrwx 1 system sys 1101824 Feb 10 2016 UTIL_NO_DETAIL_REPORT.rdf
-rwxrwxrwx 1 dev dev 614400 Feb 16 2016 UTIL_NO301.rdf >>>> this is my Issue
What do we need to show the files which do not have the expected owner?

You can use the find command:
find . ! -user system
It will show all files not owned by system in the current directory.
You can also choose to see recent files: -mtime -10 will show only files modified less than 10 days ago.
find . -mtime -10 ! -user system
You can also restrict to files only, avoiding to display directories with -type f:
find . -mtime -10 -type f ! -user system

Related

Change directory using relative path

When I open terminal, my working directory is a/b/c/
and my shell script is placed under a/b/d/e/f/ which gets triggered through Autosys.
I want to change my working directory from a/b/c/ to a/b/d/e/f/ using relative path.
Currently I'm hard coding cd a/b/d/e/f/. I don't want to do it anymore. Could you please let me know how can this be achieved.
cd ../d/e/f/
The trick being the .. which is the "parent directory" of the one you're in
You can see a reference to it (including its permissions) if you use ls -a or more completely
$ ls -lhaF
total 0
drwxr-xr-x 20 user group xxB Jun 15 00:00 ./
drwxr-xr-x 3 user group xxB Jun 15 00:00 ../
-rw-r--r-- 1 user group xxB Jun 15 00:00 e/

Changing permission of a list of file s in a directory meeting certain conditions?

I currently have to change the permission of all the files meeting the criteria g=000 (meaning group has no reading permission, no writing permission and not execution permission) which are in a directory containing ~50 files. I'm with Linux and work on the terminal, using Shell command.
As an example, here are the first 6 (my name have been replaced by user):
-r--r----- 1 user user 0 Sep 23 19:06 fichier_1
-r-x----r- 1 user user 0 Sep 23 19:06 fichier_10
-r--r----- 1 user user 0 Sep 23 19:06 fichier_11
-rwxr----- 1 user user 0 Sep 23 19:06 fichier_12
-r-x---r-- 1 user user 0 Sep 23 19:06 fichier_13
-rw---x--- 1 user user 0 Sep 23 19:06 fichier_14
If they meet the criteria g=---, they need to have all their 'other' permissions removed too, but the user permission have to stay the same. In this case, the files would now look like this (The 2nd and the 5nd files lost all 'others' permissions):
-r--r----- 1 user user 0 Sep 23 19:06 fichier_1
-r-x------ 1 user user 0 Sep 23 19:06 fichier_10
-r--r----- 1 user user 0 Sep 23 19:06 fichier_11
-rwxr----- 1 user user 0 Sep 23 19:06 fichier_12
-r-x------ 1 user user 0 Sep 23 19:06 fichier_13
-rw---x--- 1 user user 0 Sep 23 19:06 fichier_14
I have to only use 1 command, so I can't do them one by one. I tried to use the find and chmod command, but I simply can't seem to make the find command work to find all files with g=--- ( or 000).
My first attempt was this:
$ find /home/mael/tp1_inf1070/World/permissions -type f -perm g=000 -exec chmod o= {} \;
Which gave:
find: invalid mode ‘g=000’
It doesn't work with simply g=--- or just 'g=' either.
If I try to just do the first step,
$ find -perm 'g=000'
I don't get any output.
I could just do:
$ find -perm 700, 600, 400, 707, 704, 706, 707
To find all the files with no group permission, but then how to apply chmod to those files so that all their 'others' permissions get removed, but their user's permission stays the same?
Any idea on how to proceed? Thanks.
Try out to adopt the following to your needs:
find . -not -perm /g=r -and -not -perm /g=w -and -not -perm /g=x -exec chmod o-rwx {} \;
This should find all files, without group permissions and will remove any permissions for world (others).

listing files in UNIX owned by a particular user

How do I list the files owned by a particular user in UNIX ?.
If I use ls - l command in a shared directory ,it lists all the files with the details .This shared directory contains many files created by many users in a group and I am in a situation where I want to see the files created only by a particular user. Is there any listing command to give username as the input.
Refer below example,
command : ls - l
drwxr-xr-x 2 user_1 main 4.0K Feb 12 16:43 proj_1
drwxrws--- 6 user_2 main 20M Feb 18 11:07 proj_2
drwxr-xr-x 3 user_1 main 1.3M Feb 18 00:18 proj_3
drwxrwsr-x 2 user_2 main 8.0K Dec 27 01:23 proj_4
drwxrwsr-x 2 user_3 main 8.1K Dec 27 01:23 proj_5
I am looking for a command to display only the files created by the user_2 with my expected output as below ,
drwxrws--- 6 user_2 main 20M Feb 18 11:07 proj_2
drwxrwsr-x 2 user_2 main 8.0K Dec 27 01:23 proj_4
Kindly let me know if there is a way .
It should be possible to use awk togheter with ls -l
ls -l | awk '$3=="user_2" { print $0 }'
this will print all lines where third field (user) matches "user_2"
You simply can use the findcommand like this:
find . -maxdepth 1 -user some_user -exec ls -lsad {} \;
Why the options are used:
maxdepth we only want to see current directory level
user we only want to see files owned by given user
exec lets do something with the found file
What we want do with the file:
ls -lsad gives you the long list of current file, if it is a directory, don't go into it.

Linux: Finding Newly Added Files

I am trying to obtain a backup of 'newly' added files to a Fedora system. Files can be copied through a Windows Samba share and appear to retain the original created timestamp. However, because it retains this timestamp I am having issues identifying which files were newly added to the system.
Currently, the only way I can think of doing this is to have a master list snapshot of all the files on the system at a specific time. Then when I perform the backup I compare the previous snapshot with a current snapshot. It would detect files that were removed from the system but it seems excessive and I was thinking there must be an easier way to backup newly added files.
Terry
Try using find. Something like this:
find . -ctime -10
That will give you a list of files and directories, starting from within your current directory, that has had its state changed within the last 10 days.
Example:
My Downloads directory looks like this:
kobus#akira:~/Downloads$ ll
total 2025284
drwxr-xr-x 4 kobus kobus 4096 Nov 4 11:25 ./
drwxr-xr-x 41 kobus kobus 4096 Oct 30 09:26 ../
-rw-rw-r-- 1 kobus kobus 8042383 Oct 28 14:08 apache-maven-3.3.3- bin.tar.gz
drwxrwxr-x 2 kobus kobus 4096 Oct 14 09:55 ELKImages/
-rw-rw-r-- 1 kobus kobus 1469054976 Nov 4 11:25 Fedora-Live-Workstation-x86_64-23-10.iso
-rw------- 1 kobus kobus 351004 Sep 21 14:07 GrokConstructor-master.zip
drwxrwxr-x 11 kobus kobus 4096 Jul 11 2014 jboss-eap-6.3/
-rw-rw-r-- 1 kobus kobus 183399393 Oct 19 16:26 jboss-eap-6.3.0-installer.jar
-rw-rw-r-- 1 kobus kobus 158177216 Oct 19 16:26 jboss-eap-6.3.0.zip
-rw-rw-r-- 1 kobus kobus 71680110 Oct 13 13:51 jre-8u60-linux-x64.tar.gz
-rw-r--r-- 1 kobus kobus 4680 Oct 12 12:34 nginx-release-centos-7-0.el7.ngx.noarch.rpm
-rw-r--r-- 1 kobus kobus 3479765 Oct 12 14:22 ngx_openresty-1.9.3.1.tar.gz
-rw------- 1 kobus kobus 16874455 Sep 15 16:49 Oracle_VM_VirtualBox_Extension_Pack-5.0.4-102546.vbox-extpack
-rw-r--r-- 1 kobus kobus 7505310 Oct 6 10:29 sublime_text_3_build_3083_x64.tar.bz2
-rw------- 1 kobus kobus 41467245 Sep 7 10:37 tagspaces-1.12.0-linux64.tar.gz
-rw-rw-r-- 1 kobus kobus 42658300 Nov 4 10:14 tagspaces-2.0.1-linux64.tar.gz
-rw------- 1 kobus kobus 70046668 Sep 15 16:49 VirtualBox-5.0-5.0.4_102546_el7-1.x86_64.rpm
Here's what the find returns:
kobus#akira:~/Downloads$ find . -ctime -10
.
./tagspaces-2.0.1-linux64.tar.gz
./apache-maven-3.3.3-bin.tar.gz
./Fedora-Live-Workstation-x86_64-23-10.iso
kobus#akira:~/Downloads$
Most unices do not have a concept of file creation time. You can't make ls print it because the information is not recorded. If you need creation time, use a version control system: define creation time as the check-in time.
If your unix variant has a creation time, look at its documentation. For example, on Mac OS X (the only example I know of¹), use ls -tU. Windows also stores a creation time, but it's not always exposed to ports of unix utilities, for example Cygwin ls doesn't have an option to show it. The stat utility can show the creation time, called “birth time” in GNU utilities, so under Cygwin you can show files sorted by birth time with stat -c '%W %n' * | sort -k1n.
Note that the ctime (ls -lc) is not the file creation time, it's the inode change time. The inode change time is updated whenever anything about the file changes (contents or metadata) except that the ctime isn't updated when the file is merely read (even if the atime is updated). In particular, the ctime is always more recent than the mtime (file content modification time) unless the mtime has been explicitly set to a date in the future.
"Newly added files, Fedora" : The below examples will show a list with date and time.
Example, all installed packages : $ rpm -qa --last
Example, the latest 100 packages : $ rpm -qa --last | head -100
Example, create a text file : $ rpm -qa --last | head -100 >> last-100-packages.txt

Basic Unix refresher inquiry: ls -ld

I know this is really basic, but I cannot find this information
in the ls man page, and need a refresher:
$ ls -ld my.dir
drwxr-xr-x 1 smith users 4096 Oct 29 2011 my.dir
What is the meaning of the number 1 after drwxr-xr-x ?
Does it represent the number of hard links to the direcory my.dir?
I cannot remember. Where can I find this information?
Thanks,
John Goche
I found it on Wikipedia:
duuugggooo (hard link count) owner group size modification_date name
The number is the hard link count.
If you want a more UNIXy solution, type info ls. This gives more detailed information including:
`-l'
`--format=long'
`--format=verbose'
In addition to the name of each file, print the file type, file
mode bits, number of hard links, owner name, group name, size, and
timestamp (*note Formatting file timestamps::), normally the
modification time. Print question marks for information that
cannot be determined.
That is the number of named (hard links) of the file. And I suppose, there is an error here. That must be at least 2 here for a directory.
$ touch file
$ ls -l
total 0
-rw-r--r-- 1 igor igor 0 Jul 15 10:24 file
$ ln file file-link
$ ls -l
total 0
-rw-r--r-- 2 igor igor 0 Jul 15 10:24 file
-rw-r--r-- 2 igor igor 0 Jul 15 10:24 file-link
$ mkdir a
$ ls -l
total 0
drwxr-xr-x 2 igor igor 40 Jul 15 10:24 a
-rw-r--r-- 2 igor igor 0 Jul 15 10:24 file
-rw-r--r-- 2 igor igor 0 Jul 15 10:24 file-link
As you can see, as soon as you make a directory, you get 2 at the column.
When you make subdirectories in a directory, the number increases:
$ mkdir a/b
$ ls -ld a
drwxr-xr-x 3 igor igor 60 Jul 15 10:41 a
As you can see the directory has now three names ('a', '.' in it, and '..' in its subdirectory):
$ ls -id a ; cd a; ls -id .; ls -id b/..
39754633 a
39754633 .
39754633 b/..
All these three names point to the same directory (inode 39754633).
Trying to explain why for directory the initial link count value =2.
Pl. see if this helps.
Any file/directory is indentified by an inode.
Number of Hard Links = Number of references to the inode.
When a directory/file is created, one directory entry (of the
form - {myname, myinodenumber}) is created in the parent directory.
This makes the reference count of the inode for that file/directory =1.
Now when a directory is created apart from this the space for directory is also created which by default should be having two directory entries
one for the directory which is created and another for the
parent directory that is two entries of the form {., myinodenumber}
and {.., myparent'sinodenumber}.
Current directory is referred by "." and the parent is referred by ".." .
So when we create a directory the initial number of Links' value = 1+1=2,
since there are two references to myinodenumber. And the parent's number
of link value is increased by 1.

Resources