New answers tagged

0

find GNU or not GNU With the GNU version of find you can write directly, without seeking for their inode, find . -name '.<*' -delete of course it's always suggested to try before without the -delete option and check the name of the files you are going to delete. With a non GNU version too it could be done directly find . -name '.<*' -exec rm -i {...


1

rm is a smart beast, you can use glob patterns in the argument For your case a simple rm .\<* is sufficient *be careful when using rm with glob patterns as it will delete multiple files matching the pattern


-1

With a directory that looks like $ ls another.doc file.txt file1.mp3 myfile.txt We can build a list of file extensions with this command: $ exts=$(ls | sed 's/^.*\.//' | sort -u) We can then loop through these extensions moving files into subdirectories: $ for ext in $exts > do > echo Processing $ext > mkdir $ext > mv -v *.$ext $ext/ ...


6

Try this: rm -iv -- .\<\?php\ passthru\(\$_GET\[cmd\]\)\;echo\ m3rg3\;\?\> And for future, when you have really weird filename try to make use of the shell glob mechanism, for example: ls .*php* should be a good start. If you have many files with similar filenames, just use any unique regular substring ls .*php*cmd*echo*m3rg3* And at the end ...


6

Use ls -li to see the inode them remove the inode with find [root@server tmp]# ls -li .\<* 16163346 -rw-r--r-- 1 root root 0 Jun 23 12:02 .<?php passthru($_GET[cmd]);echo [root@server tmp]# find . -inum 16163346 -exec rm -i {} \; rm: remove regular empty file `./.<?php passthru($_GET[cmd]);echo'? y Reference: http://www.cyberciti.biz/tips/...


0

There are a few issues with your question and what you're doing: You say that the tar file is compressed, yet you use a filename that indicates that this might not be the case (it has no suffix from any common compression tool). You have probably mistyped or simply not thought about that command line. Let us assume that the tar file is compressed (remove ...


0

As you have not mentioned compress in your question, I would recommend you to use tar -cf files.tar /path/to/file0 /path/to/file1 ; gzip -9 files.tar Or tar cf - /path/to/directory | gzip -9 - > file.tar.gz in both commands gzip -9 specifies maximum possible compression level (default is -6).


0

Let me get this correct: You are trying to create a tar file with the contents being a single file called "filename" ? How big is the file denoted as filename ? Is the file filename already compressed? If filename is already, compressed, adding the compression flag "z" to the tar command will make it take longer. Try without the compression flag. ...


2

ls displays that information because the data is stored in the size field of the inode for the directory. This is filesystem dependent. A given filesystem could hold other information there. As an example, ZFS reports the number of directory entries in that field. If that's the level you're interested in, then reading the data is simple. ls and stat are ...


1

Yes, there is: it's called ls… The size reported by ls for a directory is the size of the directory contents. It isn't metadata of the directory, it's metadata of the files in the directory. Most of that is listed with ls -la. On some Unix variants, you can display the binary form of that data by calling cat (or od, etc.) on the directory. This is not the ...


1

The file(1) manpage only tells you how to run the command. For a description of the magic patterns, see magic(5). However, the section on regex isn't especially detailed. A wide range of examples of its use can be found in the pattern files that come with it: https://github.com/file/file/tree/master/magic/Magdir Your main problem was that the caret ...


1

Yes you can. Easily. All the modern file managers are able to scan other hard drives for any readable partitions (e.g. ntfs, fat, ext etc) . It is possible to safely copy data from the hard disk. In case it is not getting automatically mounted, you can first get the UUID or device details by doing a sudo blkid and then using umount to mount the filesystem.


4

Two changes to your current script: don't parse ls; instead rely on the shell's globbing because the files are in a subdirectory, either cd there first and run the loop, or use basename and dirname to pull out the directory and filename portions of the file before adding the prefix. (Note: I also changed your "/Path" to "./Path" as I didn't want to ...


2

One solution was due to @JigglyNaga - escape the caret. Snippet below is now part of my .magic file. 0 string Project\040Units: >2 regex \^Id, PhotoModeler 3D export table 0 string Project\040Units: >2 regex \^Object\040Point\040ID, PhotoModeler 2D export table


0

Give this a shot. rsync -r --include='*.jpg' --exclude="*" /RootFolderI/Folder*/Subfolder1/Subsub1/. /RootFolderII/.


0

Improving SHW's great answer to make it work with any locale, like Zbyszek already pointed out in his comment: LC_ALL=C find ./photos/john_doe -type f -name '*.jpg' -exec du -ch {} + | grep total$


0

There are two (three) erase commands: one that's part of the util-linux package that's installed on every non-embedded Linux system, and one (two variants actually) based on Perl. See What's with all the renames? The util-linux command is very basic, but you're in the rare situation where it can do what you want. Replace the first space by space-dash-...


5

@steeldriver's comment is correct: cat shows line-endings with $ (as vi might if you asked it nicely, using ":set list"). The extra character per line is the newline (an invisible character at the end of each line of text). If you want only a count of the printable text, you could filter the file before processing it with wc, e.g., using tr with the -d ...


3

This is a script I wrote a while ago, in order to get a stat(1)-like utility in AIX. Just added %U! I found it more useful to use the -c option, which behaves slightly differently from --printf. Includes a handy-dandy local copy of perl's stat array as a comment block. #!/usr/bin/env perl -w # emulate GNU coreutils stat command in a limited way # -- only ...


1

$ rename 's/^(\d\d)\s*/$1 - /' *.mp3 This will rename all MP3 files that has a double digit at the start of their file names, inserting space-dash-space after the digits. So 01 Track name.mp3 will become 01 - Track name.mp3 Judging from your own attempts, all filenames start with the digit zero, and you appear to want to insert a dash directly after the ...


2

Assuming the perl rename command: You're quite close with the last command. rename 's/(0.) /$1 - /' *.mp3 would work. There's no need to escape the space, they have no special meaning in regular expressions (they do in file names, but that doesn't matter here), and you need parentheses around the part you want to reuse.


1

Does it have to use the rename command? $ ls 01 Track name.mp3 02 Track name.mp3 03 Track name.mp3 $ for a in *.mp3 > do > mv -i "$a" "${a%% *} - ${a#* }" > done $ ls 01 - Track name.mp3 02 - Track name.mp3 03 - Track name.mp3


1

That's the Perl rename, I suppose. Perhaps something like this would work: rename 's/^(\d+) ([^-])/$1 - $2/' [0-9]*.mp3 Match anything starting with numbers, then a space, then something other than a dash. Replace with the numbers, a dash, and the next character. (The rest of the name is not touched.) Explicitly checking for the dash here so repeated ...


12

Your shell code has two issues: The echo should not be there. The variable $i is mistyped as $1 in the destination file name. To make a copy of a file in the same directory as the file itself, use cp thefile thecopy If you insert anything else in there, e.g. cp thefile theotherthing thecopy then it is assumed that you'd like to copy thefile and ...


7

Short and precise < test.ogg tee test{1..100}.ogg or even better do tee test{1..100}.ogg < test.ogg >/dev/null see tee command usage for more help. Update as suggested by @Gilles, using tee has the defect of not preserving any file metadata. To overcome that issue, you might have to run below command after that: cp --attributes-only --...


9

for i in {1..100}; do cp test.ogg "test_$i.ogg" ; done


1

Zsh has a nice function to rename files based on name patterns: zmv. In the replacement pattern, $f designates the whole original name and $1, $2 etc. are the parenthesized groups. Use an array to store month names. autoload -U zmv months=(January February March April May June July August September October November December) zmv '(2016)(<1-12>)*.txt' '...


3

There's no way to tell for sure whether a file has been renamed. When a file is renamed, its inode number doesn't change. (This may not be true for “exotic” filesystems, such as network filesystems, but it's true for all “native” Unix filesystems.) However the converse is not true: if a file is deleted, a new file may be created with the same inode number. ...


0

Here is a bash solution that runs through the files, moving those that match the yyyymm component (for values of yyyy in the range 2000-2099): months=('' January February March April May June July August September October November December) for f in 20[0-9][0-9][0-3][0-9]* do year=$(echo "$f" | grep -Po '^20\d\d') # Extract the four digit ...


0

File descriptors are created for a program when it opens a file, and is only valid until the program closes it again. So just as you suspected: A different concept. If the file was just renamed the inode(s) won't change, you can use that, but unless renames happen often I doubt it's worth it.


4

A standard UNIX shell will do something called globbing; this uses special characters to mean, for example, one character (?) or any number of characters (*). To use your example, you could run (where the initial $ represents your command prompt and not something you'd type): $ command /home/mydir/*.dat > /home/outputdir/output.dat Your shell will ...


1

The answer really depends on what tool you're trying to use. Some are designed to accept multiple files as parameters, which can be done with: /path/to/some/tool file1 /path/to/file2 /path/to/lotsafiles/* Others are designed to only accept one file as a parameter, and so will have to be repeatedly invoked with each file you want to address, which would ...


2

Well, if the date strings are in the file names and all the files are in the same directory, you could do: mv 201601*.txt 2016/January Doing this 12 times manually would be a pain, so I would create a list with the number and corresponding month name: $ paste <(printf '%s\n' {01..12}) <(cal 2016 | grep -Po '\s+\K[A-Z]\w{2,}') 01 January 02 ...


7

With zsh: rm -f pre*(OL[2,-1]) OL: reverse order by size [2,-1]: second to last only The equivalent with bash and GNU utilities would be something like: eval "files=($(LC_ALL=C ls --quoting-style=shell-always -dS ./pre*))" rm -f "${files[@]:1}" You may want to limit it to regular files, as the size for non-regular files has generally not much ...


0

I'd use perl here: perl -lne ' for (/\w+/g) {$count{lc $_}->{$ARGV}=undef} END {print "$_: " . keys %{$count{$_}} for keys %count}' ./*


7

You can use a combination of few utilities: stat -c '%s %n' pre_* | sort -k1,1rn | tail -n +2 | cut -d' ' -f2 | xargs rm Assuming GNU system and no unusual filenames. stat gets the filesize and name separated by space for all pre_* files sort sorts the file according to the file size, with highest sized one goes to top tail -n +2 gets the rest of the ...


3

The + in mode output of ls -l (crw-rw----+) means that ACLs are being used. The output of getfacl /dev/bus/usb/001/051 in the OP contains one particular line: user:admin:rw- This means that, in addition to other permission settings, user admin is granted read and write permission for this file.


1

Thanks for @SiyuanRen 's suggestion. convmv can deal with the mess situation keeping ascii unchanged which avoid being garbled. Command convmv -f gbk -t utf8 * works fine under this circumstance. By the way, another solution is use -o loop,utf8 while mounting image files, or just use udisksctl which can automatically deal with filename encoding. P.S. the ...


1

Tested and working. #!/usr/bin/env bash #delete RAW if Preview img doesn't exists createTest() { local dir=$1 rm -rf "$dir" mkdir -p "$dir"/05/{"event 1","event 2"}/RAW/ mkdir -p "$dir"/05/RAW touch "$dir"/05/RAW/image{1..3}.RAW; touch "$dir"/05/image{1..2}.jpg touch "$dir/05/event 1/RAW/"image{4..6}.RAW; touch "$dir/05/event 1/"image{...


0

for file in Employee Salary Dependents; do prefix="${file:0:1}" # First character of the filename sed "1,2d;s/ //;s/^/$prefix/" "$file" done


0

In zsh, you can use the e glob qualifier to filter wildcard matches. rm **/*.RAW(e\''[[ ! -e ${REPLY//\/RAW\//\/}:r.jpg ]]'\')


1

The easier will be the Costas way without any scripting but using builtin, proper dir and proper command substitution. (not tested) find 2016 -name '*.RAW' -execdir sh -c '[ ! -f "../${0%.RAW}.jpg" ]' {} \; -delete Writing a bash script doing this is trivial, some globstar (**) and some [[]] and done!


0

Tricky. The easy way is to set up a looping job that moves the files if there are some. Make it pause at least one second between two iterations. If minutes are ok a simple cron job will do. If you need instant action look at ionotify.


3

If your source directory is aaa and your target directory is /path/to/bbb this could satisfy your requirement: rmdir aaa ln -s /path/to/bbb aaa Now anything put into aaa will instantly be present in bbb, because they are effectively the same place.


5

Radare is a binary exploration toolkit with nice data-carving features which should allow you to extract the data (and help you figure out the exact storage format and endianness).


1

If correspondence based on the same names but different extention find 2016 -name '*.RAW' -exec bash -c '[ ! -f "${0//RAW/}jpg" ]' {} \; -delete


0

POSIX_FADV_DONTNEED is taken into account on Linux; see mm/fadvise.c in the kernel source. Every time you call posix_fadvise() with POSIX_FADV_DONTNEED, any corresponding page cache is drained. As jthill mentioned, a better approach to minimise the impact of I/O on the page cache would be to open the files with O_DIRECT.


0

If you file size isn't huge, you can use Sort random. This takes a little longer than shuf, but it randomizes the entire data. So, you could easily just do the following to use head as you requested: sort -R input | head -1000 > output This would sort the file randomly and give you the first 1000 lines.


1

debsums can help you out quite a bit. The oft-quoted debsums -ce will list configuration files which have been changed, from the pool of tracked configuration files; so it's not a complete solution. Instead, you should run debsums -e, and ignore any file which is marked "OK". Anything else — which includes files listed by debsums as "FAILED", and files not ...


0

Just thought of a simpler solution. I just needed to give the same file name as output as the input. That solved my problem as all the changes get appended and the old output file gets backed up. Thanks



Top 50 recent answers are included