Hello how to delete a directory named by error "*" ? It is dangerous!
drwxr-xr-x 3 root root 4096 Aug 31 16:04 *
rmdir '*' seems to work. Note the single quotes. (You'll have to pre-delete its contents.)
Related
The answer maybe obvious to you, but I am beginning to run my first logrotate instance.
The configuration in /etc/logrotate.d
/mnt/nginx/logs/access.log {
size 1k
dateext
missingok
rotate 10
compress
delaycompress
notifempty
create 640 root root
sharedscripts
postrotate
[ -f /opt/nginx/logs/nginx.pid ] && kill -USR1 `cat /opt/nginx/logs/nginx.pid`
endscript
}
Then I tested it with
sudo /usr/sbin/logrotate -dvf /etc/logrotate.d/nginx
And got following
reading config file /etc/logrotate.d/nginx
reading config info for /mnt/nginx/logs/access.log
Handling 1 logs
rotating pattern: /mnt/nginx/logs/access.log forced from command line (10 rotations)
empty log files are not rotated, old logs are removed
considering log /mnt/nginx/logs/access.log
log needs rotating
rotating log /mnt/nginx/logs/access.log, log->rotateCount is 10
dateext suffix '-20140724'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding logs to compress failed
glob finding old rotated logs failed
renaming /mnt/nginx/logs/access.log to /mnt/nginx/logs/access.log-20140724
creating new /mnt/nginx/logs/access.log mode = 0640 uid = 0 gid = 0
running postrotate script
running script with arg /mnt/nginx/logs/access.log : "
[ -f /opt/nginx/logs/nginx.pid ] && kill -USR1 `cat /opt/nginx/logs/nginx.pid`
"
Before test
total 84K
-rw-r--r-- 1 root root 51K Jul 22 15:05 access.log
-rw-r--r-- 1 root root 24K Jul 15 17:02 error.log
After test
total 84K
-rw-r--r-- 1 root root 51K Jul 22 15:05 access.log
-rw-r--r-- 1 root root 24K Jul 15 17:02 error.log
There was exactly nothing changed. And it didn't complain errors.
Can you please help this?
Thanks
I made a mistake.
-d option should not be used.
But since it actions as such, why not call it "dry" run?
I am working on Solaris 10 machine. In that i cannot able to untar my file. Logs are given below. Anyone please suggest what may be the issue? I can able to create tar file but unable to untar. :(
bash-3.2# ls -lrth ConfigCheck-120614-KL.out*
-rw-r--r-- 1 root root 144K Jun 12 17:15 ConfigCheck-120614-KL.out
-rwxrwxrwx 1 root root 146K Jun 16 16:49 ConfigCheck-120614-KL.out.tar
bash-3.2# tar xvf ConfigCheck-120614-KL.out.tar
tar: extract not authorized
bash-3.2# tar tvf ConfigCheck-120614-KL.out.tar
-rw-r--r-- 0/0 147377 Jun 12 17:15 2014 ConfigCheck-120614-KL.out
Solaris 11 tar will fail with that error message if you are running as uid 0 but do not have the Media Restore profile set up in the RBAC configuration.
Unless you're trying to restore from backup, you should normally be untarring files as a normal user, not root, to avoid accidentally overwriting critical system files.
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)
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Say I have a folder "root". I own this folder, and I make it such that for others (which includes the user "user2", the permissions are r-x)
Within root I have another folder "bin". I change the owner of "bin" to the user "user2", and give him rwx permissions.
Will user2 be able to create new files in the folder "bin"? Does not having write for "root" affect his ability to do so?
Also, can user2 delete the entire folder "bin" from "root"? (I don't want him to be able to do so - he just needs to create/delete files within the folder bin!)
Yes. Because user2 has access (x) permission on root and owns bin, he can create files in root/bin. If the permissions do not currently include write permission for the owner, the owner (user2) can change the directory permissions so that the permissions do include write permission.
No. Because user2 does not have write permission in root, user2 cannot remove bin from root.
He can write inside of bin, but not outside of it. The scope of his rwx permissions resides within that folder unless you otherwise modify his permissions.
Understanding what you stated you have something like this:
drwxr-xr-x 10 root root 22 Dec 26 23:04 root
where the contents of "root" are like this:
cd root
ls -la
drwxr-xr-x 10 root root 22 Dec 26 23:04 .
drwxr-xr-x 29 root root 34 Oct 24 06:13 ..
drwx------ 2 user2 root 3 Oct 23 10:28 bin
The permissions on "root" have to be at least 555 (r-xr-xr-x) because it would not work if your "root" directory permissions were 500 or 550 (see below) because "user2" would not be allowed to enter the directory "root" (there are exceptions, like 550 would work if "user2" is member of the "root" group).
# This would not work, user2 cannot enter the "root" directory
drwx------ 10 root root 22 Dec 26 23:04 root
To understand all this security stuff you first have to realize that a directory is really, and simply, a file. The major difference between a directory and a file is the meaning of the "x" permission. If the user does not have "read" permission, he can't see the files in the directory. So, lets put the access to 711, like this:
drwx--x--x 10 root root 22 Dec 26 23:04 root
Now let's try to see what files are in the directory. You can't:
$ ls -la root
root: Permission denied
total 3
However, you can enter it (because of the "x" execute right) but you still can not see inside:
$ cd root
$ ls -la
.: Permission denied
total 3
But if you are aware that inside there exists a directory you have access to, you can enter it:
$ cd bin # Ps. Here we assume we did the 'cd root' above already
$ ls -la
total 6
drwxr-xr-x 2 user2 root 2 Mar 14 14:57 .
drwx--x--x 3 root root 3 Mar 14 14:57 ..
And "user2" can do, as the owner, anything he wants. The access to "bin" could even be "700", as long as you are the owner, you can enter it. Because the access is 755 (in our example), anyone can enter the directory "bin", but only "user2" can create files in it. Modifying or reading those possible files will depend on the access "user2" gives them.
"user2" cannot remove the "bin" directory, even if he owns it, because he does not own the "file" (i.e. the "root" directory) where the name of the "bin" directory is written. That is owned by the "root" user who is the only one allowed to write there.
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\ *