Tag Info

New answers tagged

1

You can either replace the backslash by a space as you show in the example: sed -e 's/\\/ /g' or you can remove it: sed -e 's/\\//g' Because backslash is a special character in regex you have to escape it by backslash: \\.


1

You have to escape the backslash. Try this: sed 's/\\//g'


0

First, gain access to the terminal and execute ls -al file with file being the file you want to convert back into an ACTUAL folder. If there are files and sub-directories listed it means your "file" was previously a folder with real content and you may continue: Execute: sudo chmod 700 / OR sudo chmod 700 file Restart the system and regain terminal ...


2

The other answers miss three points: Don't ever do this: /usr/bin/find /var/www/cache/blah/ |xargs /bin/rm -f >/dev/null 2>&1 because when you have a file with a space in it, rm will attempt to remove two files, with surprising results. If you insist on doing it this way, assuming you are using GNU find and xargs, you want: /usr/bin/find ...


7

There are a few differences in the behavior of the command lines: The find command line would delete files recursively in subdirectories, the rm command line wouldn't. You need to consider whether or not you want to recurse. The find command line would delete all files, if possible. The rm command line might skip files based on the shell's settings like ...


8

Some reasons I can think about why they used find + xargs: Handling the case when you have too many cache files, leading to an error if you run only one rm command. Globbing * does not expand hidden files. Working recursively. But this find + xargs is not efficient, since when they didn't add any filter, so find result will contain directories along with ...


0

Perhaps run rsync via strace/truss and see if you get an error back from the chown() syscall, and also to confirm that chown() has the correct path and UID/GID.


0

I believe the command you have is the one that gives this required information. I did the below testing to verify if your command returns the expected output. touch sample_file stat -c%b sample_file ## The output is 0 as we have no contents inside the file. 0 Now, append some contents to the file. echo "Hey there, this line goes to my file" >> ...


1

This file is owned by user db and group db: Access: (0444/-r--r--r--) Uid: ( 1001/db) Gid: ( 1001/db) But is world readable (444). The directory hierarchy it is in is not, but it should be readable by group dbp, unless /home/db has non-default permissions. This may be the case since your umask (027) is stricter than normal (002). Otherwise, it would ...


3

This can easily be done with diff. For example: $ ls -l foo/ total 2132 -rwxr-xr-x 1 terdon terdon 1029624 Nov 18 13:13 bash -rwxr-xr-x 1 terdon terdon 1029624 Nov 18 13:13 bash2 -rwxr-xr-x 1 terdon terdon 118280 Nov 18 13:13 ls $ ls -l bar/ total 1124 -rwxr-xr-x 1 terdon terdon 1029624 Nov 18 13:14 bash -rwxr-xr-x 1 terdon terdon 118280 Nov 18 13:14 ls ...


0

You should select which time you need %y modification %w creation %z change or any combination: stat * --printf="%n\t%y %z\n" | grep -vF $(date -d "last Saturday" +%F) | cut -f1 Also choice what infomation you need and compose --printf= line. Or you can use just find command find -maxdepth 1 -type f -daystart \ ! -mtime $[$(date +%d)-$(date -d ...


1

Simpler: find . -maxdepth 1 -printf '%Ta\t%p\n' | grep -v -i '^sat' ref: This answer.


1

A way to do this : $ LANG=C find . -maxdepth 1 -printf '%p %AA\n' | awk '$NF=="Saturday"{next}{$NF=""}1' I assume we don't print files for all Saturdays. This is or not what you expect.


0

wdiff is a special case due to it requiring 2 filename arguments, but for all commands that only require 1 argument and which stubbornly refuse to take anything but a filename argument, there are 2 options: The filename '-' (that is, a minus sign) works about 1/2 of the time. It seems to depend upon the command in question and whether the developer of the ...


1

In one line grep -f <(ls "A") <(ls "B") | xargs -I'{}' rm "B/{}" but it work depends on file name only and may affect to empty subdirs. To avoid this use find -type f -maxdepth 1 instead of ls. For more secure check use @KasyA recepie.


1

In 3 lines: $ delfrom=/home/KasiyA/dirB # delete from $ cd /home/KasiyA/dirA # matched from /dirA$ find . -type f -exec cmp -s '{}' "$delfrom/{}" \; -exec echo rm -v "$delfrom/{}" \; In a test: $ ls -1 ~/dirA dupfile file1inA $ ls -1 ~/dirB dupfile file1inB /dirA$ find . -type f -exec cmp -s '{}' "$delfrom/{}" \; -exec echo rm -v "$delfrom/{}" \; ...


2

One way: #!/bin/bash cd ~/B for file in ~/A/* do file1=$(basename "$file") [ -f "$file1" ] && { echo "deleting $file1 "; rm -- "$file1"; } done


3

incr() { var=$(< "$1") var=$((var + 1)) echo $var > "$1" } is_zero() { var=$(< "$1") [[ var -eq 0 ]] } decr is left as an exercise for the reader.


0

Also has the right to be (with results in .out files): find . -name '*.txt' -exec sh -c (echo HEAD;cat {};echo FOOT) > {}.out' \; Another, more elaborated variant - source files replaced with result: find . -name '*.txt' -exec sh -c (echo HEAD;cat {};echo FOOT) > {}.tmp && mv {}.tmp {}' \; -print


1

If f1 is a subset of f2 then f1 - f2 is an empty set. Building on that we can write an is_subset function and a function derived from it. As per Set difference between 2 text files sort_files () { f1_sorted="$1.sorted" f2_sorted="$2.sorted" if [ ! -f $f1_sorted ]; then cat $1 | sort | uniq > $f1_sorted fi if [ ! -f $f2_sorted ]; then ...


4

I don't know of any place where the kernel exposes the filenames associated with the blocks that it has cached. According to this answer http://stackoverflow.com/a/4941371 The best you could probably do even with a custom kernel module would be to get a list of inodes and devices. From there you would still likely need to walk the filesystem looking for ...


0

I don't think you can do that just like this. You will have to be more creative and e.g. split manually. Fill USB stick with first 32G: tar czf - / | dd if=/dev/stdin of=/usbstick/bla bs=32k count=100k iflag=fullblock Write the first 32G of the resulting tar to the destination dd if=/usbstick/bla of=/tarfile bs=32k count=100k Fill USB stick with next ...


43

The correct syntax in bash is the following: rm /tmp/!(lost+found) As @goldilocks wrote in the comments, the original command makes an expansion on the query (it deletes all the files in the /tmp folder, then goes on, and deletes all the files in the current working folder, in your case the home folder). You can try to check if you can recover some of ...


26

The !(lost+found) in your rm command was probably the fatal mistake: 1978 rm -rf /tmp/* !(lost+found) 1979 sudo rm -rf /tmp/* !(lost+found) I don't know exactly bash is doing with that, but this command prints everything in my /tmp and also everything my current directory, which is currently ~: echo /tmp/* !(lost+found)


11

An example: $ touch f1 $ ln f1 f2 $ ln f1 f3 $ ln -s f1 s1 $ ln -s f2 s2 $ ln -s ./././f3 s3 $ ln -s s3 s4 $ ln s4 s5 $ ls -li total 0 10802124 -rw-r--r-- 3 stephane stephane 0 Nov 12 19:55 f1 10802124 -rw-r--r-- 3 stephane stephane 0 Nov 12 19:55 f2 10802124 -rw-r--r-- 3 stephane stephane 0 Nov 12 19:55 f3 10802345 lrwxrwxrwx 1 stephane stephane 2 Nov 12 ...


19

Jim's answer explains how to test for a symlink: by using test's -L test. But testing for a "hard link" is, well, strictly speaking not what you want. Hard links work because of how Unix handles files: each file is represented by a single inode. Then a single inode has zero or more names or directory entries or, technically, hard links (what you're calling ...


9

Using the -h and -L operators. -h file true if file is a symbolic link -L file true if file is a symbolic link http://www.mkssoftware.com/docs/man1/test.1.asp According to this SO thread, they have the same behavior, but -L is preferred.


0

Read the instructions that should be present in the same place where you found the download link. If you can't find any instructions, you can run the file command to see what kind of a file it is. If the file is executable (either a script or a native code binary), make it executable and run it. From a command line in the directory where you've downloaded ...


0

If you can use ls, then I assume you can use builtin bash functionality too. Using pure bash to count all entries in the current directory: $ num_entries () ( # Define a function to: > shopt -s nullglob # expand * to empty string if no files > shopt -s dotglob # include .files in * expansion > a=( * ) # create array ...


3

Since, you want to decipher from the output that you have got, we will try and simplify things. ls -ld drwxr-xr-x 4 root root 4096 Nov 11 14:29 . Now, ls -ld on a directory gives me the output as above. Now, the number 4 is something that you need to concentrate on. The 4 corresponds to: the entry for that directory in its parent directory; the ...


0

You may combine a couple of approaches Number of files in a directory ls -l | grep "^-" | wc -l Walk through subdirectories find ./subdirectory -type d put together in one command find ./subdirectory -type d | xargs -I{} sh -c "ls -l {} | grep -c '^-'" Will recursively result a count of files restisting in the directories. Of course there a ...


0

In a simple case this works: ls -A1 | wc -l


0

Another safe approach that should work on any GNU system and Busybox: tail -n5 "$(stat -c "%Y %n" ./* | sort -nk1,1 | cut -d ' ' -f 2- | tail -n1)" That will work on most things but if your file names can contain newlines, use this instead (GNU only, still breaks if your files end in newlines): tail -n5 "$(stat --printf "%Y %n\0" ./* | sort ...


7

With the zsh shell: tail -n 5 ./*.aff(D.om[1]) With other shells, it's quite difficult to come up with something reliable if you don't want to make assumptions on what file names may contain. For instance, the bash equivalent, if you're on a recent GNU system would be: find . -maxdepth 1 -name '*.aff' -type f -printf '%T@:%p\0' | sort -rzn | sed -zn ...


5

Assuming file names don't contain newline characters and that all the *.aff files are regular files: ls -t1d -- *.aff | head -n 1 gives you the name of the most recently modified .aff-file. If you want the last 5 lines just do: tail -n 5 -- "$(ls -t1d -- *.aff | head -n 1)"


1

To find all files in directory $1 that are older than 1000 minutes and younger than 2000 minutes: find "$1" -maxdepth 1 -type f -mmin +1000 -mmin -2000 If you want to search recursively into subdirectories, remove -maxdepth 1. If you prefer to specify time in integral days, rather than minutes, use -mtime: find . -maxdepth 1 -type f -mtime +20 -mtime ...


1

LVM doesn't know anything about files. It provides a big block of storage. It's up to the filesystem to organize this block to store files, and the filesystem doesn't know (nor want to care) about which files are on which physical volume. Even if a file is entirely contained in one physical volume (which for most filesystems is guaranteed if the file is ...


2

Sockets are files. You can use read and write on a socket: they're equivalent to calling recv and send with flags=0. You close them with close. You can move them around with dup and friends if you need to shuffle file descriptors. You can set some flags with fcntl, and use stdio buffering after calling fdopen. The list goes on. Very importantly, you can call ...


1

You can add the -wholename test with a not (!) to remove the directory. For example: find /mystuff/temp/videos ! -wholename 'mystuff/folder' -type d -exec chmod 777 {} \; From the man page: -wholename pattern File name matches shell pattern pattern. The metacharacters do not treat '/' or '.' specially; so, for example, find . ...


1

Try: find /mystuff/temp/videos -type d ! -name 'folder1' -exec chmod 777 {} + A note that you should not set 777 permission, it's a big hole in security.


5

If you stat a socket, you will see that it has an inode number and other characteristics of regular files, so I would classify it as a file on the filesystem. Example: # file live live: socket # stat live File: `live' Size: 0 Blocks: 0 IO Block: 4096 socket Device: fc03h/64515d Inode: 198817 Links: 1 Access: ...


1

LVM can split file under multiple volume, and in some case it's a needed comportement. LVM work as physical part, just upper partitioning shemas, consequently it's filesystem agnostic and don't know the concept of file that managed by filesystem. To convince youi better, LVM is capable of make agregation like RAID0 does, xKbites from the first disk, next ...


10

"Everything is a file" is just an overstatement. It was novel in 1970s and it was a primary distinguishing characteristic of UNIX. But it's just a marketing concept, not a real foundation of UNIX, because it's obviously not true. It's not beneficial or sensible to treat EVERYTHING as a file. Is CPU a file? Does your program read() a CPU to get a new ...


21

sockets use different APIs That's not entirely true. There are some additional functions for use with sockets, but you can use, e.g., normal read() and write() on a socket fd. how does this "Everything is a file" apply here? In the sense that a file descriptor is involved. If your definition of "file" is a discrete sequence of bytes stored in a ...


0

ls -1 -a | ls *.foo | wc -l Where foo is your extension.


2

Bash command: for i in *; do echo "${i##*.}"; done | uniq -c


0

I think a simple ls *.extension should do the trick :) To count them, you can use ls *.extension -1 | wc -l


0

Some script with bash-builtins and assotiative array declare -A F_TYPE unset F_TYPE while IFS=" ," read b c d f do n="$b${c:+ $c}${d:+ $d}" F_TYPE[$n]=$[${F_TYPE[$n]}+1] done < <(file -b *) for i in "${!F_TYPE[@]}" do echo "$i = ${F_TYPE[$i]}" done echo "Totally ${#F_TYPE[@]} types"


1

One way: find . -maxdepth 1 -type f | sort -u -t. -k3 | wc -l Explanation: find . -maxdepth 1 -type f: find all normal files in current directory sort -u -t. -k3: sort the output on 3 filed with . as a field separator and print only first of equal lines wc -l: count the lines Edit If you are using zsh shell then you can run echo ${(u)$(echo ...


0

Without inotifywait you can use this little script and a cron job (every minute or so): #!/usr/bin/env bash # # Provides : Check if a file is changed # # Limitations : none # Options : none # Requirements : bash, md5sum, cut # # Modified : 11|07|2014 # Author : ItsMe # Reply to : n/a in public # # Editor : joe # ...



Top 50 recent answers are included