Create symlinks with lowercase names from uppercase files and directories [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I have a directory that contains files and folders with names that contain uppercase letters.
I was wondering if it's possible using bash to create symlinks with the same name but in lowercase.
-rw-r--r-- 1 root root 570 Sep 22 00:00 AiA_SA_2014_08_10
-rw-r--r-- 1 root root 575 Sep 12 00:00 AiA_SA_Lite_2014_09_07
-rw-r--r-- 1 root root 570 Sep 22 00:00 AiA_SA_2014_08_10
to
-rw-r--r-- 1 root root 570 Sep 22 00:00 AiA_SA_2014_08_10
-rw-r--r-- 1 root root x Sep 22 00:00 aia_sa_2014_08_10-> AiA_SA_2014_08_10
-rw-r--r-- 1 root root 575 Sep 12 00:00 AiA_SA_Lite_2014_09_07
-rw-r--r-- 1 root root x Sep 12 00:00 aia_sa_lite_2014_09_07 -> AiA_SA_Lite_2014_09_07
-rw-r--r-- 1 root root 570 Sep 22 00:00 AiA_SA_2014_08_10
-rw-r--r-- 1 root root x Sep 22 00:00 aia_sa_2014_08_10 -> AiA_SA_2014_08_10

In recent bashes, you can use the ,, parameter expansion to turn a string to lowercase:
shopt -s extglob
for file in *?([:upper:])* ; do
ln -s "$file" "${file,,}"
done
The extglob pattern only selects files with an uppercase letter in their names.

declare -l lower
for upper in *; do lower="$upper"; ln -s "$upper" "$lower"; done

Yes, it's possible.
Using a simple loop:
for i in *; do
[[ -f $i ]] || continue # in case of empty directory
lcname=${i,,} # Covert the name to lowercase
ln -s "$i" "$lcname"
done
If you are not running from current directory, you can give fullpath in for loop.

parallel ln -s {} '{=$_=lc($_)=}' ::: *

Related

Logfiles ending with ".1" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
Why my logsfiles ending with ".1" ?
Its just a new file for log ?
-rw-r----- 1 root adm 0 Mar 14 10:56 auth.log
-rw-r----- 1 root adm 8998827 Mar 14 00:00 auth.log.1
-rw-r----- 1 root adm 5241 Mar 14 10:55 daemon.log
-rw-r----- 1 root adm 97769 Mar 14 00:00 daemon.log.1
-rw-r----- 1 root adm 0 Mar 14 00:00 debug
-rw-r----- 1 root adm 16853 Mar 11 20:51 debug.1
-rw-r----- 1 root adm 0 Mar 14 00:00 kern.log
-rw-r----- 1 root adm 87015 Mar 11 20:51 kern.log.1
-rw-rw-r-- 1 root utmp 292292 Mar 14 10:39 lastlog
-rw-r----- 1 root adm 154 Mar 14 00:00 messages
-rw-r----- 1 root adm 73418 Mar 14 00:00 messages.1
-rw-r----- 1 root adm 0 Mar 14 00:00 user.log
-rw-r----- 1 root adm 2168 Mar 11 20:51 user.log.1
It looks like logrotate in action. That's how it works:
Log rotation is the process that renames a current log file (e.g.,
auth.log becomes auth.log.1) and sets up a new log file (e.g.,
auth.log) for new log entries.
Rotating log files is important for several reasons. First, you
probably don't want older log files eating up too much of your disk
space. Second, when you need to analyze log data, you probably don't
want those log files to be extremely large and cumbersome. And last,
organizing log files by date probably makes spotting and analyzing
changes quite a bit easier (e.g., comparing last week's log data to
this week's).
You didn't mention the OS in question: this article, for example, described how one can set up and configure logrotate on Ubuntu 16.04.

Mac OSX file permissions has '#' - how to remove that '#' [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
How can I remove that '#' character from the file permissions?
'#' in file permissions for Mac/OSX machines, is used to show that an extended attribute is set with this file.
Tried chmod 755 galaxy-ansible.yml but that didn't help.
Tried echo | chmod -E galaxy-ansible.yml, didn't help (even with using sudo).
Tried xattr -d galaxy-ansible.yml, that didn't help either (even with using sudo).
I even did the above operations as root user, still '#' character is not going away from file's permissions.
[arun#MacBook-Pro-2 ~/aks/anisble] $ ls -l# galaxy-ansible.yml
-rwxr-xr-x# 1 arun staff 270 Dec 22 12:31 galaxy-ansible.yml
com.apple.quarantine 67
My ~/aks folder is mapped to a CentOS vagrant box and if I'm on the vagrant box, doing ls -l doesn't give me '#' (as it's not a Max/OSX machine):
-rwxr-xr-x. 1 vagrant vagrant 270 Dec 22 00:12 galaxy-ansible.yml
On my Mac/OSX machine, there are other .yml files but those don't have '#' in the file permissions so I'm trying to remove '#' from galaxy-ansible.yml file (on Mac machine).
Right now the whole roles/.. folder has '#' character for any folder/files.
-rwxr-xr-x# 1 arun staff 1132 Dec 21 17:12 README.md
drwxr-xr-x# 3 arun staff 102 Dec 21 17:12 defaults
drwxr-xr-x# 3 arun staff 102 Dec 21 17:12 handlers
drwxr-xr-x# 4 arun staff 136 Dec 21 17:12 meta
drwxr-xr-x# 5 arun staff 170 Dec 21 17:12 tasks
drwxr-xr-x# 7 arun staff 238 Dec 21 17:12 templates
The following commands helped in clearing the extended attribute at file / folder(recursive) level.
xattr -c <yourfilename>
or
xattr -cr <yourfoldername>

What is the deference between 'ls -lh' and 'ls -si'? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I have executed both the comments but the size seems different in both output.
ls -lh
total 147M
-rw------- 1 root root 3.4K Sep 30 14:58 anaconda-ks.cfg
-rw-r--r-- 1 root root 247 Sep 30 14:58 install.post.log
-rw-r--r-- 1 root root 54 Sep 30 14:58 install.postnochroot.log
-rw-r--r-- 1 root root 147M Sep 30 14:58 jdk-7u79-linux-x64.gz
ls -l --si
total 154M
-rw------- 1 root root 3.5k Sep 30 14:58 anaconda-ks.cfg
-rw-r--r-- 1 root root 247 Sep 30 14:58 install.post.log
-rw-r--r-- 1 root root 54 Sep 30 14:58 install.postnochroot.log
-rw-r--r-- 1 root root 154M Sep 30 14:58 jdk-7u79-linux-x64.gz
If you would have checked the manpage for ls with the command man ls you would have seen the following:
-l use a long listing format
-h, --human-readable
with -l and/or -s, print human readable sizes (e.g., 1K 234M
2G)
-i, --inode
print the index number of each file
-s, --size
print the allocated size of each file, in blocks
So you see, each parameter just defines what and how information will be put to the screen. What you see (the difference in size) is the -h or --human-readable command, which will output more readable filesizes instead of printing always the bytes. Using -s will print the filesize in blocks on your HDD, which depends on the block size of your filesystem. From the information provided, i would say your filesystem has a 1kb blocksize. So the real content of the file would be 3.4kb, but must fill up the blocks, so on your disk the file requires 4kb or 4 blocks of space.

Linux memory issue [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I have a problem on my server.
When i try to start my server, it says that "there no left space on device"
If i execute the command "df", I see that on directory if full.
/dev/mapper/owegdc_vg-owegdc_logs_lv
10321208 9797004 0 100% /opt/application/owegdc/logs
When i get to the logs directory here what i see
ls -lrta
total 368
drwxr-x--- 2 oweadm grpowe 16384 Jan 15 2014 lost+found
drwxr-x--- 7 oweadm grpowe 4096 Jun 18 11:55 .
drwxr-xr-x 2 oweadm grpowe 12288 Aug 4 10:20 apache
drwxr-xr-x 2 oweadm grpowe 4096 Aug 5 00:56 batches
drwxr-xr-x 2 oweadm grpowe 4096 Sep 10 13:43 expl
drwxr-xr-x 2 oweadm grpowe 327680 Sep 10 13:50 jonas
drwxr-xr-x 11 oweadm grpowe 4096 Sep 10 13:50 ..
du -sk
9642792 .
I tried things like 'lsof' but it didn't work...
Do you have an idea ?
Thx
You could just try something like
du | sort -h -r
That would list the directories on your disk, ordered by their size descending. The first directory in the output list is the biggest one.
Better, if you're looking for large single files instead of a directory, this answer on Unix & Linux gives useful information, especially this:
find . -type f | xargs du -h | sort -rn
The output is the same, but it lists files instead of dirs.

Shell command to delete folders less than N days [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
This is slightly different question/variation to this question
Remove all directories whose created on time is older than N days.
Don't consider the sub-directories/files within the directory.
Ex:
drwxrwxr-x 6 test test 4096 Aug 26 14:42 2.1.6-SNAPSHOT_201408261440_1
drwxrwxr-x 6 test test 4096 Sep 1 05:13 2.1.6-SNAPSHOT_201408281233_1
drwxrwxr-x 6 test test 4096 Sep 1 10:06 2.1.6-SNAPSHOT_201409011001_1
drwxrwxr-x 6 test test 4096 Sep 1 15:58 2.1.6-SNAPSHOT_201409011554_1
drwxrwxr-x 6 test test 4096 Sep 2 15:11 2.2.0-SNAPSHOT_201409021508_1
drwxrwxr-x 6 test test 4096 Sep 2 15:18 2.2.0-SNAPSHOT_201409021515_1
drwxrwxr-x 6 test test 4096 Sep 5 13:05 2.2.0-SNAPSHOT_201409051303_1
drwxrwxr-x 6 test test 4096 Sep 5 15:32 2.1.6-SNAPSHOT_201409051528_1
drwxrwxr-x 6 test test 4096 Sep 8 11:54 2.1.6-SNAPSHOT_201409081152_1
I should be able to delete all folders in this path whose created on is older than N days. The inside folder might have updated files/sub-directories which are new, it doesn't matter.
Assuming you want to delete old directories:
N=4
find . -type d -mtime +$N -exec rm -fr {} +
A depth-first search would ensure that sub-directories are removed before the directories that contain them, but might end up altering the modify time on the directory before find looks at it, which would mean that directories that were old are no longer counted as old. However, conversely, the rm may end up trying to remove directories it has already removed, but the -f option ensures this does not end up with error reports.
You might want to consult Explaining find … -mtime command for information about the meaning of +$N vs -$N vs $N (where N is assumed to hold a number).

Resources