Tag Info

New answers tagged

1

It seems more likely that it means that any permissions are masked by 004, that is, other users cannot read the file. This would serve to protect the file from other users on the system (to some degree).


0

To do this with ls robustly you should not split on anything but the path delimiter - that's what it's for. IFS=/; set -f set -- $(ls -dt ./*) shift That will sort all non-dot files in the current directory and place the results in the shell array $@. Given a POSIX ls, this is not susceptible to any kind of filename mangling whatsoever: special characters ...


4

The permission mask 004 means that the file can only be read by processes that are not running as the same user or as the same group as the FTP server. This is rather unusual: usually the user has more rights than the group, and the group has more rights than others. Normally the user can change the permissions, so it's pointless to give more restrictive ...


2

In zsh it's as easy as array=(*.sh(Nom)) The glob qualifier om causes the matches to be sorted by modification time (newest first), and N forces the array to be empty if there is no match (instead of causing an error). In other shells such as bash, there's no good way of sorting by time. You can use ls -t, but that can break because the output is ...


0

Find honestly is the best way to go about this, but what I tend to do out of habit is grep -r something I know is in the file. It is definitely not the professional way to do things, but hey another option doesn't hurt. Quick tip, if you want to find commands by what they do, you can type man -k "describe what it does"


3

find <path>/. -type f -size 1033c ! -perm -0001 -ls


5

The octal permissions mask of 004 corresponds to a symbolic permissions mask of u=,g=,o=r which means that the (u)ser who owns the file cannot read it or write to it or execute it, and neither can other users in the same (g)roup as the user who owns the file. Only (o)ther users who are neither the owner, nor in the same group as the owner, are able to read ...


4

Yes, but the file is owned by the user. So the client itself has the 0 permission (user) on the file and cannot read it. You can test this yourself: touch myTestFile; chmod 004 myTestFile; echo test > myTestFile; chmod 700 myTestFile; echo test > myTestFile; The third step will raise an error.


0

An array might not be necessary: for f in $(ls -t *.sh); do echo "$f" done If an array is necessary: files=( $(ls -t *.sh) ) Doing things with the array: # Echo the number of elements in the array: echo "${#files[@]}" # Echo the values of each array element: echo "${files[@]}" # Echo just the first array element: echo "${files[0]}" # Assign the ...


0

As Chazelas points out, your script would fail if wildcard expansion matches more than one file. However, there is a trick I use (even I don't like it very much) to get around: PATTERN=(/*.txt) if [ -f ${PATTERN[0]} ]; then ... fi How it works? Wildcard expansion will match an array of filenames, we get the first one if there are some, otherwise null if ...


0

Use this: text=[your text];echo $text>file;echo $text Example: This: tx=My text;echo $tx>logfile;echo $tx Will result in this standard output: My text and the contents of logfile will be: My text If you want a shorter solution, make this file (copy and paste): #!/bin/sh if [ $# = 3 ];then echo $1>$2 echo $1 else echo You must specify 2 arguments ...


1

How do I configure a data scrubbing daemon that automatically detects when I randomly lose a HDD sector causing an archive to not pass it's checksum verification, then to copy a backup onto another sector. It's built in to Btrfs. Try: btrfs scrub start It has never yet happened to me that an error was found, but I expect that if one is found then: ...


1

Of course you can. Firstly tar in most cases does not include compression, it hands that off to a helper (if it supports it at all). At first that helper was compress (.tar.Z). I have also seen gzip (.tar.gz or .tgz), bzip2 (.tar.bz2), infozip's zip and unzip tools (.tar.zip), and some I cant rember the official names for (.tar.lha, .tar.lhz, .tar.zoo, ...


1

Posting comment as answer: for d in directory_*; do cp -R "$d" "tmp_$d"; done Credits @drewbenn


4

For files which are not device that is not the minor number but the size in bytes. The size of a directory depends on which filesystem is used, and how many entries (i.e. files or subdirectories) are in it.


2

Those are not minor numbers (as they are for the device nodes). This answer explains each field in turn.


0

I don't have access to OSX so this is a wild guess... but you can try other techniques to delete files, rather than relying on the shell's globbing to match. Try: find . -not -type d -print -delete or even find . -not -type d -print | perl -nle 'print; unlink'


0

When you delete bytes from a file you have to rewrite it. That will be O(L) time where L is the length of the file. You will never achieve O(n) in a sane file system. You might reach < O(n) when n is divisible by the file systems block size as this operation will just remove some reserved inodes from the directory entry. (In the ideal case, where a ...


1

That's not a problem on your system, it's the way Chrome works. It isn't leaking memory or files or anything, that's data that Chrome is currently using. Chrome uses many separate processes (not exactly one per tab, but that's the general idea). Some of these processes need to exchange data. They do this via shared memory. Chrome implements (at least some ...


0

tee requires you to open up a stream to /dev/null, you can get away doing this with a simple cat cat <<EOF >> $OUTFILE foo bar EOF Save your keyboard!


2

The correct and complete answer is: To modify access time only with the "touch" command, you must use "-a" parameter, otherwise the command will modify the modification time too. For example, to add 3 hours: touch -a -r test_file -d '+3 hour' test_file From man touch: Update the access and modification times of each FILE to the current time. -a ...


5

Welcome to the future. It is now 2012, and in your brand new Fedora version 17 /bin is now merely a symbolic link to /usr/bin. There is no separate /bin directory. Further reading Joe 'Zonker' Brockmeier (2012-01-30). The Ever-Changing Linux Filesystems: Merging Directories into /usr. linux.com. Harald Hoyer and Kay Sievers (2012). UsrMove. Fedora ...


1

when you say it is a different system, I suppose it is into another computer and you wanna copy by network, it's it? Exists a lot of ways to make this copy, to suggest one which is better to you, you need be more specific of the systems and the copy process. Exemple: you just wanna move full data into a system to another, or you need update frequently this ...


0

tr -d \\n <infile | tr \~ \\n | paste -d~ - - - - - - - - - - - - - - That will work.


0

It's not clear how to decide whether to join a split field with a space or without a space. 06<NL>-JAN-10 needs to have the newline removed, whereas varieties<NL>up to needs to have it replaced by a space. Ignoring the above concern, we can arrive at this prototype Awk command: $ awk 'BEGIN { RS = "~" } { gsub(/\n/,"",$0); ...


2

There is a tool called logrotate read the manual page man logrotate it is started by cron and probably already cleaning the log directory you can add your own configurataion files to /etc/logrotate.d


0

Use inotify if you need to know immediately If you need to know about the newly created files immediately, you can actually wait for the event of creating a file in a directory, or in a directory tree, using the inotify API on linux (see man 7 inotify): You would combine this with parts of the other solutions to find out the detailed information about the ...


2

As this is a executable script, it is good to place it at /usr/bin or /usr/local/bin Advantage: avoid typing full path of the script like /var/opt/anything/my_script ever you want to test it from terminal , just type my_script I think there is no standard of doing this, place it anywhere (obviously not at /dev, /proc, /sys, /var/www, etc.) you like, ...


2

Startup scripts and assets are usually put in the user's home directory. (The home directory can either be found by getent passwd username or by logging in as the user and inspecting the value of $HOME.)


1

The permissions for group take priority over permissions for other. And in turn, permissions for user take priority over both. You're not the owner but you are in group1, so those are the permissions that are checked. Generally, permissions rarely become less restrictive when going from user to group to other. In your scenario, if you want members of group1 ...


2

With zsh: setopt extendedglob # if not already in ~/.zshrc rm Task.<10->.store.log To avoid the arguments list too long: autoload zargs # best in ~/.zshrc zargs Task.<10->.store.log -- rm


5

A POSIX one, can handle file which contain newline in filename: find . -name 'Task.??*.store.log' -exec rm -f {} +


3

find . -name 'Task.??*.store.log' | xargs rm -f


0

In most cases you can avoid your if looping structure by: chmod 777 -- my_dir/[^ab].so my_dir/*??.so chown igor -- my_dir/[^ab].so my_dir/*??.so


3

If you don't want to process hidden files: for f in my_dir/*.so; do case $f in (*/[ab].so) : ;; (*) chmod 777 -- "$f"; chown igor -- "$f" ;; esac done Note that setting file permission to 777 is very bad ideal, causing security hole and making chown command later wasted.


0

sed -i is for inplace editing: from man sed -i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if SUFFIX supplied) sed is a good choice, but you could also use awk awk '/<your_pattern>/' foo > bar Example $ cat foo foo bar foobar bar foo bar bar foo $ awk '/foobar/' foo > bar $ cat bar foo bar foobar


0

You can use grep. Lets say you want search in the file source_file , and the second file where you have the lines that you want to search from is input_file. Use grep -f input_file source_file > output_file Let's say your source_file is Humpty Dumpty sat on a wall Humpty Dumpty had a great fall All the King's horses and All the ...


1

re-build the dynamic linker runtime bindings (as root): ldconfig -v | grep libCmp and it should a) output your lib (meaning it was found) b) correctly install needed symlinks, so the lib will be found in the future a missing build-id is no problem.


0

If you have recently added libCmp. As root you could try: ldconfig -v ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib). The cache is used by the run-time linker, ld.so or ...


3

Don't use sed -i - it would overwrite your original file. Use grep instead. grep "text to find" input.txt > output.txt


2

sed outputs to stdout by default. To output to a file, redirect sed's stdout to a file using the > operator (if you want to create a new file) or using the >> operator (if you want to append the output to an already existing file): sed '/text/' inputfile > outputfile sed '/text/' inputfile >> outputfile


4

Use find -exec for recursive touch, with command line args for dirs to process. #!/bin/sh for i in "$@"; do find "$i" -type f -exec touch -r {} -d '+3 hour' {} \; done You can run it like this: ./script.sh /path/to/dir1 /path/to/dir2


4

At least three different utilities imaginatively named rename(1) are floating around in the Linux waters: (1) the one that came with util-linux, (2) an older Perl script by Larry Wall further munged by Tom Christiansen, and (3) a newer Perl script evolved from the former and included with Unicode::Tussle. As far as I can tell, what you want can't be done ...


2

If (and this is a big if) you are using the rename that uses a perl expression to modify filenames you can achieve what I think you want like this: rename 's/(\d+)/"a" x $1/e' * The e flag is explained in perldoc perlre. It modifies the interpretation of right hand side so that it is evaluated as a perl expresssion.


1

Logrotate has the rotate parameter that specifies how many logs to save.


1

A shell alias is used as an interactive part of the shell. When you call sudo you leave the shell and execute a command. You could either enter an interactive shell with sudo -s, define your aliases and use them, or you have to rewrite your aliases as commands or functions, for example use a folder /root/alias-cmds and write the command /root/alias-cmds/ll: ...


0

The ownership of symbolic links don't matter. Its the referenced entitiy which does. That said, use find -l to discover symbolic links in a directory tree. Use chown -h and/or chmod -h to operate on the symbolic link. find . -type l -exec chown -h root:root {} +


3

For large files using sort will be slow. I wrote a short C program to solve the equivalent problem (see this gist for Makefile with tests): #include <stdio.h> #define BUFFERLEN 4096 int main(){ // This program reads standard input and calculate frequencies of different // bytes and present the frequences for each byte value upon exit. // ...


3

With pdftk and GNU coreutils Determine the number of pages in the PDF file, then call shuf to generate a randomized list of page numbers, and call pdftk again to extract the given sequence of pages. pdftk original.pdf cat $(shuf 1-$(pdftk original.pdf dump_data | awk '$1=="NumberOfPages:" {print $2}')) output randomized.pdf With Python and PyPdf ...


1

We will use pdftk to perform operations on the pdf document. Create a temporary working directory: mkdir tmp Split the pdf document in many one page documents: pdftk original.pdf burst output tmp/pg_%02d.pdf Rename the one-page document with random names: for name in tmp/*.pdf; do mv "tmp/$name" tmp/$(echo "$name" | sha1sum | cut -f1 -d' ').pdf ...



Top 50 recent answers are included