Tag Info

New answers tagged

1

A directory is special in that it has the 'd' in its mode, telling the filesystem that it should interpret its contents as a list of other files contained within the directory, rather than a regular file that is just a sequence of bytes to be read by the application. That is all.


3

My answer is mere reminiscence, but in 199x vintage Unixes, of which there were many, directories were files, just marked "directory" somewhere in the on-disk inode. You could open a directory with something like open(".", O_RDONLY) and get back a usable file descriptor. You could parse the contents if you scrounged through /usr/include and found the ...


10

Many entities in *nix style (and other) operating systems are considered files, or have a defining file-like aspect, even though they are not necessarily a sequence of bytes stored in a filesystem. Exactly how directories are implemented depends on the kind of filesystem, but generally what they contain, considered as a list, is a sequence of stored bytes, ...


10

In the Unix Way of Doing Things: everything is a file. A directory is one (of many) type of special file. It doesn't contain data. Instead, it contains pointers to all of the files that are contained within the directory. Other types of special files: links sockets devices But because they are considered "files", you can ls them and rename them and ...


0

Try vim-way: $ ex -s +'%!cut -c 1-10' -cxa file.txt This will edit the file in-place (so do the backup first).


1

Alternative: cpio (cd /my/big/folder && find . -depth -print0 | cpio -0o > myfolder.cpio) Unpacking to current directory: cpio -id < myfolder.cpio Caveats: If use find /my/big/folder instead of cd, the archive will contain full paths and extraction will try to follow them; Big files (> 2GB) may be a problem;


0

The easiest way I found was to select all torrents in Transmission, then go to the menu Torrent > Set Location and then choose the desired location for torrents. After which, Transmission takes care of moving torrents.


12

Use tar: tar -cf my_big_folder.tar /my/big/folder Restore the archive with tar -xf my_big_folder.tar -C / -C will change to the root directory to restore your archive since the archive created above contains absolute paths. EDIT: Due to the relatively big size of the archive, it'd be best to send it [directly] to its final location, using SSH or a mount ...


2

A trivial but simpler solution is to chmod 700 a directory and operate inside it.


2

One way to do this is to make a blank insecure.key file first and chmod it. touch insecure.key chmod 600 insecure.key Which makes the directory look like total 28 drwxr-xr-x 2 flyte flyte 4096 Apr 17 11:44 . drwxr-xr-x 12 flyte flyte 4096 Apr 17 11:44 .. -rw------- 1 flyte flyte 0 Apr 17 11:44 insecure.key -rw------- 1 flyte flyte 1746 Apr 17 11:42 ...


5

You can try to set umask before converting it umask 077; openssl rsa -in secure.key -out insecure.key Edit: To not affect other files in the current shell environment by the umask setting execute it in a subshell: ( umask 077; openssl rsa -in secure.key -out insecure.key )


1

Well, it may not be spelled out in the documentation you linked to,  but the intent of the A attribute is that the file system/operating system should not update the access time when the file is read.  But the touch program exists specifically for changing the times in inodes; after all, its default behavior is to update the mod time without actually ...


0

As @Kevin suggested, you can use wc command to count lines in a file. However, wc -l test.txt will include the file name in the result. You can use: wc -l < test.txt to just get the number of lines without file name in it. Give it a try.


3

I think you can get away with using split's --filter=COMMAND. ... | split -b <SIZE> -d - part --filter=./split-filter where ./split-filter is something like #!/bin/bash set -e n="${FILE#part}" case $((10#$n%3)) in 0) dd bs=64K >"path1/$FILE" ;; 1) dd bs=64K >"path2/$FILE" ;; 2) dd bs=64K ...


1

An awk solution: awk '!a[$0]++'


0

What exactly is the question here? You should add some detail on your invocation pattern of rsync to get any meaningful assistance. I've used rsync for years without problems. I think it's safe to say that any apparent corruption is due to improper usage of this versatile tool. If you don't pass -c, rsync skips based on modification time and size. Even if ...


6

Try this: touch -d"April 13 3 AM" file1 touch -d"April 13 9 AM" file2 find . -newer file1 ! -newer file2 -exec grep -l "pcV6URY" {} + rm file1 file2 How it works find can work directly with times but touch handles human-style dates better: touch -d"April 13 3 AM" file1; touch -d"April 13 9 AM" file2 This creates two files to mark the beginning and end ...


0

Looking at this answer and that one in particular, I ended up running this command which removed all the unwanted files: 7z l archive.zip | awk ' {print $6} ' | awk ' function basename(file) { sub(".*/", "", file) return file } {print basename($1)} ' | xargs rm -rf


1

Rsync copies files. That's what it does. Even if you tell it to remove source files, it still copies them first, it never moves them, even when the destination happens to be on the same filesystem. The mv utility from GNU coreutils has an option -u to move files only if the destination is older than the source or doesn't exist yet. This is similar to ...


8

You need the write permission on a directory to create or remove files in it, but not to write to a file in it. Most shell commands, when given an output file, simply open that file for writing, and replace the data that was previously in the file. The > redirection operator truncates the existing file (i.e. deletes the existing file content, resulting in ...


1

No. You can't use sed's or perl's -i switch to edit files in place in a read-only directory. As you correctly assumed, you won't be allowed to create the necessary temporary files: $ ls -ld read_only/ dr-xr-xr-x 2 terdon terdon 4096 Apr 13 02:16 read_only/ $ ls -l read_only/file -rw-r--r-- 1 terdon terdon 3 Apr 13 02:16 read_only/file $ sed -i 's/a/A/' ...


3

Perl's Tie::File module offers true in-place edit functionality: perl -MTie::File -e ' tie @a,"Tie::File","your_file_here"; # Do something... ' This makes the elements of @a into the lines of your file and any changes done to @a are reflected in the file even if the file is in a read-only directory.


3

If the directory is read-only but the files within that directory are read/write, then there is nothing stopping you from overwriting those files. From a script you can write to the files using usual redirection > and >> as well as overwriting them using cp. What you cannot do is to create a new file in the directory and rename it on top of an ...


4

Without something like SELinux, root can always write to files; since you're running as root you can always write. If you're not running as root, then the permissions apply; if file exists and is not writable, then > file or >> file will fail. If file does not exist, then it will be created if the parent directory is writable.


2

rsync copies files, it never moves them. Combinations of find and mv will likely do what you want.


1

Use the find command to enumerate files in a directory and its subdirectories recursively. There are several ways to rename files. You can use the Linux rename command: find Music -depth -name '*_000' -exec rename _000 '' {} \; This removes the first occurrence of _000 in each file name. Beware that if you had files whose name contains _000 in the middle, ...


2

Although mikesrv solution is much better and safer I think this can be done also with rename: find Music/ -type f -name '*_000' -print0 | xargs -r0 rename -v '_000' '' But there are still potential problems as mentioned, for example album_00020_000 will be renamed to album20 which obviously is not the desired behaviour. I think on debian distribution was ...


2

cd Music/.. && mkdir Music2 && pax -'rwls|\([^/]\)_000$|\1|p' Music Music2 If run from Music's parent directory, the above commands will create a directory called Music2 then mirror Music's path structure in Music2 w/ hardlinks while removing any occurrence of _000 found at the tail of any filename therein. Afterward you'll have ...


2

Assuming a ZIP archive, as commonly found on MS‐DOS systems, under a unix command line prompt one might do: % unzip -p -a files.zip | awk ... where the ellipsis are replaced by your arguments to awk. Data input is received from standard input via the pipe. Replace unzip with the appropriate command if you're using another compression method and update ...


1

Your question suggests that you want to base64 encode the content of a variable: $ TEXT=test $ ENCODED=$(echo "$TEXT" | base64) $ echo "$ENCODED" dGVzdAo=


3

You don't need a text file, you can use this: base64 <<< "$var" or echo "$var" | base64 Example: var="abcde" base64 <<< "$var" results YWJjZGUK


1

You can use Here Strings. It is supported by bash, zsh and other common shells. Example: The grep command only work with files but here we are passing a variable using Here Strings to be searched for pattern by grep. $ str="this is a test line" $ grep -o "test" <<< "$str" test As far as your command is concerned you can use: $ base64 ...


10

The system does not track that information. Every time the file is modified, the new modification time overwrites the previous one. Depending on what exactly you need to do, various alternate solutions might apply, such as using a version control system, or having a daemon that watches for changes using inotify. But all of those solutions would rely on ...


0

With pax: pax -'rws|/|_|' -- */u_ex150407.log target/dir pax is the standard file-archiver specified by POSIX. Unfortunately - though it is required in the Linux Standard Base and has been for a few version increments of same - for whatever reason, many distribtions do not package it with the default installation as both standards require. I consider this ...


0

You're doing: if the $DIR/0folder doesn't exist, make a directory with that name. Just change -f (file) by -d (directory). That should solve your problem, now you could be interested on some tips that people had given here but that is apart.


2

Neither -d or -f is useful here for robust tests - because they're just opposite sides of the same coin. touch file; [ ! -d file ] && mkdir file mkdir: cannot create directory ‘file’: File exists See? Better would be [ -e ... ] || mkdir ... to check for existence, which would at least save on the error above, but even that has its issues - like ...


0

Zsh comes with a function called zmv that makes it easy to move or copy files and apply pattern-based transformations on the name. Put this in your .zshrc (or run it on the command line): autoload -U zmv alias zcp='zmv -C' alias zln='zmv -L' Then your copy-with-renaming can be done with any of the following equivalent commands: zcp 'Logfiles/(*)/(*.log)' ...


1

Read the manual. The -p option will make a directory and intermediate directories as required if it doesn't exist or silently fail. Assuming that you are not processing thousands of files then you could just do mkdir -p "${DIR}/0folder or if you feel the need to test then [ -d "${DIR}/0folder" ] || mkdir -p "${DIR}/0folder"


3

From the manual (man bash) under CONDITIONAL EXPRESSIONS: -f file True if file exists and is a regular file. -d file True if file exists and is a directory. So, to check for the existence of a directory (not a file)... if [[ ! -d "$DIR/0folder" ]] ; then mkdir "$DIR/0folder" fi


12

The -f in your test is checking if FILE exists and is a regular file. What you need is -d to test if FILE exists and is a directory. if [ ! -d "$DIR/0folder" ] then mkdir "$DIR/0folder" fi It is not mandatory to check if a directory exists though. According to the man page of mkdir we see the following man mkdir | grep -A1 -- -p -p, --parents ...


1

It's the same. You just have to provide the parent directory rather than the prefix of files. In your example, it would be: find /path/to -type f -mtime +5 -exec rm {} \; This will delete all the files older than 5 days which are under /path/to and its sub-directories. To delete empty sub-directories, refer to @Costas comment above.


5

You will receive in destination_dir files with full path from / find /path/git_directory -type f -iname "*.py" \ -exec cp --parents -t /path/destination_dir {} + Other solution is rsync rsync -Rr --prune-empty-dirs \ --include="*.py" \ --include="**/" \ --exclude="*" \ /path/git_directory ...


0

You can use following script to copy files from one location to another with modified name. Note: In following script we have hard-coded two values. /Logfiles/ :- change Logfiles name to valid folder name from which you have to copy files. /tmp/ :- It is a directory under which you want to copy files. Change this directory name according to your ...


0

With zsh: tar cf foo.tar *(m-1)


4

On a POSIX filesystem, every file has a user (the file's owner), a group, and permissions for the user, the group, and everyone else. For every user, access to a given file is determined as follows: if the user is the file's owner, the owner permissions apply; if the user is a member of the file's group, the group permissions apply; in all other cases, ...


2

find . -name '*_*' Thanks to Stéphane Chazelas as noted in the comments above!


3

find . -name PKA.dump -type f -exec awk ' FNR == 20 {print; nextfile}' {} + nextfile, where available (GNU awk and some others like FreeBSD's and recent versions of mawk and soon to be added to the standard) will skip to the next file. Where not, it will be ignored (it's just like dereferencing a nextfile variable); it will still work but read the files ...


0

Well if you have license to some disk cloning tools, use them to do a disk-to-disk clone on a virtual PC is usually much faster (if they do understand the semantic of the FS instead of verbatim copying). (I use Symantec Ghost for my Windows guest VMs but I'm not sure if it supports EXT filesystems.)


1

You can try with awk: awk 'FNR == NR { v[$1] = 0; next; } { v[$4]++; } END { for (elem in v) { print elem, v[elem]; } }' File-1 File-2 >outfile So result will be: 201503301616|9b8791b3-f860-409f-aad0-24debf834c1b|11.233.18.29.677220869928387637969 1 201503301616|9b8791b3-f860-409f-aad0-24debf834c1b|12.233.18.29.677220869928387637969 2 ...


2

The short answer using tree would be tree -PF *.dat You can also use (As I explained in my comment ) the GNUfind command. find . -type f -name '*.dat' -printf '|__ %P\n' You don't need GNUfind though. You can also use the following which is posix. find . -type f -name '*.dat' -print



Top 50 recent answers are included