Tag Info

New answers tagged

2

Files are inodes. However, you can create files that are not linked to any directory and still use an inode. For instance: zsh -c 'repeat 1000 ((repeat 1000 {exec {fd}> file; rm file} exec sleep 1000 >&-) | cat)' would (eventually) use up 1,000,000 inodes. Those inodes would be of deleted files that have not been reclaimed yet since ...


1

The multi-line answers above didn't suit my desire for a one-line solution and not modifying the environment. Here is a generic one-liner that may work for you: echo $(ls FOO* 2>/dev/null | wc -w) the /dev/null is because ls throws an error if there's no file. This just ignores ls and counts the number of files found based on the number of "words" ...


0

As mentioned in the question: What does size of a directory mean in output of 'ls -l' command? The metadata of the folder is always stored in blocks, so it allocates 4kb even if there is not much data that needs to be stored. -Duplicate Question.


0

You can get the first line from a file like: read -r varname <file In the case where a file contains less than one \newline - or if the file does not exist, or can otherwise not be read - the above command will return other than 0. Else it will return 0 and $varname will contain the file's first line. In fact, if the file cannot be read for any reason ...


1

I have try to re-produce the case and have found that in case where the last line in the file don't finish with newline (where can happend for example if echo -n '#!/bin/bash' > /script used) the operation echo "del x.txt" >>/script can produce cat /script #!/bin/bashdel x.txt To avoid this you can use sed instead echo sed -i '$a\del x.txt' ...


1

You can test to see if a file is empty by using unix test -s. Example below... if [ -s $file ] then echo "File size is zero" else echo "File size is not zero" fi


0

As a secondary answer, when fdupes is not available, a more efficient way would use md5 to get the hash, and sort and uniq to find duplicates without a double shell loop Something like : (put all on one line, without comments) find . -type f -name '*.txt' // get recursively all .txt files | xargs md5sum // compute the md5 sum | awk '{print ...


2

This script will create as many files as you have inodes available on your / filesystem: while [ $(df --output=iavail / | tail -n1) -gt 0 ]; do touch $((i++)); done As far as I know, there is no way to take up inodes without using files or directories, that's what they're for after all. Node that the inodes will remain in use after the script is ...


5

Yes you can consume all the inodes of a system. They are a limited resource just like diskspace is, and they're pre-allocated when you perform a mkfs.ext4, for example. You can use tools such as tune2fs -l <device> or df -i <path> to see how many are allocated and used. Example $ df -i / Filesystem Inodes IUsed IFree IUse% ...


0

If fdupes isn't available, you could also use: for first in *.txt do for second in *.txt do if diff $first $second >/dev/null 2>&1 && [ "$first" != "$second" ] then #echo $first and $second match. Deleting ${second}. # Optional, uncomment to use. rm $second fi done done Note: ...


1

If you have fdupes, it can list all the duplicated files in your folder. You could refer to this online tutorial on how to use the fdupes command. Testing I created 3 files named file1, file2 and file3 with file1 and file2 having exactly similar contents. Now, I executed my command as, fdupes -rdN . Where (quoting from the above refered link), ...


1

You can do this with ls, sort, tail and cut. Start with renaming bash_history to bash_history 1 so all files have a number. Then run the following to copy the next file: #!/bin/bash D=~/Desktop/Coding/Bash\ Histories num=$(ls "$D" | cut -d ' ' -f 2 | sort -nr | head -1) num=$(( num + 1 )) cp ~/.bash_history "$D/bash_history $num" The ls $D just lists ...


2

awk 'NR == FNR {first[$0];next}; ! ($0 in first)' "$file2" "$file1" >> "$file2" That assumes that the file names don't contain = characters. If they might, on systems that support /dev/fd/n, you could do: awk 'NR == FNR {first[$0];next}; ! ($0 in first)' \ /dev/fd/3 3< "$file2" /dev/fd/4 4< "$file1" >> "$file2" Note that if lines ...


1

If the file is created for enough short amount of time, you can run the following command on separate terminal before running the script: while true; do cat /tmp/drush_* 2>/dev/null && break; done Where /tmp/drush_* is your pattern. The advantage is that it's quick and you don't have to install any external tools (if you don't have e.g. ...


4

This is due to the way you're using inotifywatch, and the way the tool itself works. When you run inotifywatch -r /tmp, you start watching /tmp and all the files that are already in it. When you create a file inside /tmp, the directory metadata is updated to contain the new file's inode number, which means that the change happens on /tmp, not /tmp/test-1. ...


0

ldd dumps the dependencies of Elf files. All Elf files start with the bytes \x7F 'E' 'L' 'F', which is probably the fastest way to test them. However, I'm not aware of any option in find which reads the content of the file. find mainly just looks at the metadata in the directory listing, like filename, mode bits, and so on. However, in order to run an ...


1

As far as I know, there is no way to restrict a user from changing the modification time of a file. Changing the modification time is a normal feature, use for example when extracting files from an archive or copying them from another machine. Instead of looking at the modification time, look at the inode change time (ctime). Pass the option -c to ls to ...


2

drush is likely using that temp file in one of two ways: It's creating the file; using it; and then leaving it around. It's creating the file; using it; and then cleaning it up. My guess is that you wouldn't be asking the question in case (1) because you could just inspect the file manually after the fact. So then the problem is that you want to inspect ...


2

You could set up a script that uses inotify (inotify-tools on Debian) and have it scan any changes of files in a particular directory. Then filter out the filename and cat it to a log file.


1

The command apt-get purge is mostly identical to apt-get remove, but purge also deletes any configuration files. Often you will want to keep those as they can hold local changes that will be lost permanently if you delete them. You can use apt-file list <package_name> to list out what files belong to a specific package. These files are the ones that ...


5

Since you say you're using node.js, I assume you'd be using fs.rename() (or fs.renameSync()) to rename the files. This node.js method is documented to use the rename(2) system call, which does not touch the file itself in any way, but merely changes the name under which it is listed in the file system: "rename() renames a file, moving it between ...


0

The most important thing is to match the patterns that exist and stick to it. Get to an answer without waste time mulling it over. I understand the irony that I am answering this question ; Apple follows /Library/Extensions/SomeExtension.file so I set up my working directory like that too: Projects/Client/Project/thing.extension Incidentally, the frontend ...


0

There are several problems, including: Your code as posted doesn't hang You use the -l flag to ls, which means you'll be looking for files named -rw-r--r-- and such You should avoid parsing the output of ls at all And there's no need to test the output of grep, you can just use the exit status. From man grep: EXIT STATUS The exit status is 0 if ...


2

You could simplify this significantly (and avoid the nasty problems inherent in parsing ls) by doing something like: file_nm=$(find . -maxdepth 1 -name "*abc*"); [ -e "$file_nm" ] && grep -q "search_txt" "$file_nm" && echo "string found" || echo "string not found" However, like your original example, that will fail if you have ...


0

Try: grep "search_txt" /dev/null "$file_nm" Feeding /dev/null to grep will make it work even if $file_nm is not existed, because grep always has at least one file - which is /dev/null - to work on.


0

You should test if $file_nm is empty before running the grep if [ -n "$file_nn" ]; will return True if $file_nm is NOT empty.


4

Here's a quick Python program that should output your desired schema, using recursion. Should work in both Python 2 and 3 (although I only tested on 2). The first argument is the directory to descend into, or by default, the script will use the current directory. #!/usr/bin/env python import os import errno def path_hierarchy(path): hierarchy = { ...


3

This will not work as it unlikely that your hosts mapped in filesystem (i.e. Windows C: drive, so most likely NTFS) supports the full range of permission bits that Linux git expects. In a similar situation I have exported a Linux directory via Samba and used that from Windows and Linux without problems. This however has the disadvantage that you cannot ...


27

As long as you don't move the file across file-system borders, the operation should be safe. This is due to the mechanism, how »moving« actually is done. If you mv a file on the same file-system, the file isn't actually touched, but only the file-system entry is changed. $ mv foo bar actually does something like $ ln foo bar $ rm foo This would ...


5

Linux normally doesn't do any locking (contrary to windows). This has many advantages, but if you must lock a file, you have several options. I suggest flock: apply or remove an advisory lock on an open file. This utility manages flock(2) locks from within shell scripts or from the command line. For a single command (or entire script), you can use ...


1

You can prevent hackers from using PHP code to change modification time (mtime) of files that are writeable by your web server by disabling those PHP functions (such as touch) using [disable_functions][1] option in php.ini configuration file. However, tracking modification time is not the right approach because the modification time of files do not change ...


4

You can try imagemagicks identify command: http://www.imagemagick.org/script/identify.php Example: $ identify rose.jpg rose.jpg JPEG 640x480 sRGB 87kb 0.050u 0:01 Hope it helps.


13

You can use file tool: $ file file.png file.png: PNG image data, 734 x 73, 8-bit/color RGB, non-interlaced $ mv file.png file.txt $ file file.txt file.txt: PNG image data, 734 x 73, 8-bit/color RGB, non-interlaced


2

It is possible without being root but you should set SUID for your program. There is 2 way to do it which are exactly same anyway. chmod u+s [program] chmod 4755 [program] You may want to see SETUID Also If you want to handle this in C : You Should check setuid function And If you want to do it in bash : You should check setuid on shell scripts


0

Using a Version Control System such as git you can "check in" or "commit" any number of versions of your file. Git is probably one of the easiest Version Control Systems to get to grips with, because it doesn't require the use of a separate server; all the work can be done on your own local machine,and there is plenty of tutorial information available on the ...


6

If there is no built-in capability in the program that you use, to overlay new information in some way over a base file, you have to resolve this on the filesystem level, transparently to the application using the file. Because of your space requirement a revision control system would not suffice, although it provides you with multiple versions. One thing ...


0

To find the difference there is command diff - compare files line by line. You can store differences to diff-file and at any time can apply it by patch - apply a diff file to an original. But in any way you should first to make a second file to make changes (you can delete it after receive diff-file). If diff can't work with binary files even with --text ...


4

To give a binary permission to run things as root, you need to set the "sticky bit" on the binary. Normally after compiling, you might see: # ls -l print -rwxr-xr-x 1 mark mark 111 24 Oct 17:32 print Setting the set-uid (sticky) bit can be done using and octal mode, or symbolically (note that you will need "root" privileges in order to change the ...


0

chown root:root name_of_binary chmod 4755 name_of_binary


2

Here is a (dumb) way to remove your file using mv: mv file /tmp init 6 Of course, rm file is significantly faster, more efficient and reliable, and less intrusive.


9

mv other-file file-to-be-deleted mv file-to-be-deleted other-file


0

Something is removed if it is no longer there where it used to be, that doesn't necessarily imply that it no longer exists or is inaccessible via other means. Both when using computers and in real life we often remove things by first moving them to the trash, from where it still can be retrieved. Literally a simple mv filename ...


4

The symlinks appearing in red indicates "broken" links - i.e. the target does not exist. This seems to indicate that whatever was providing /c is not mounted. You need to figure out the device that provides that data and mount it.


5

As Vivian suggested, the -t option of ls tells it to sort files by modification time (most recent first, by default; reversed if you add -r).  This is most commonly used (at least in my experience) to sort the files in a directory, but it can also be applied to a list of files on the command line.  And wildcards (“globs”) produce a list of files on the ...


1

This does almost exactly what you want, except it leaves off the trailing / on the directory names. find . -maxdepth 2 -name file1.php -printf '%T@ %h (last modified %Td/%Tm/%TY %Tk:%TM)\n' \ | sort -k 1n | sed 's/^[^ ]* .\///' Credit where credit is due. This is adapted from shlck's answer here. Edit: All of my %A should have been %T


1

Yes it is quite possible. This will give you files which are modified in last 60 minutes: $ find /domain -type f -mmin -60 or this will give you files which are sorted by modify time. $ find /domain -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort -r Edit #1 If you have file extensions like you said '.php', add this: -name '*.php' And I found this ...


0

This Python script will do it, sort of: #!/usr/bin/env python3 import fileinput for line in fileinput.input(mode='rb'): print(line) There's one problem that I hadn't realized: the binary data may itself contain the separator character, messing up the output.


3

Install the inotify-tools package on your distribution. Use the command inotifywait to create a continuous lookup on the desired directory. Ex: inotifywait -m -r -e create /src_dir. This tool can watch other aspects of the filesystem(attributes change, close write, move, delete), so, lets stick with the file creation thing. Preapare the notification and ...


2

Your script does not have /tmp/console_test opened, the cat process does. Your script is reading from a pipe that is connected to the cat process; that's what you're seeing in your question. Search for the cat process and check that one out. You probably want something like this: while read x; do echo "received $x" eval "$x" done < ...


3

You can use openssl to encrypt and decrypt using key based symmetric ciphers. For example: openssl enc -in foo.bar \ -aes-256-cbc \ -pass stdin > foo.bar.enc This encrypts foo.bar to foo.bar.enc (you can use the -out switch to specify the output file, instead of redirecting stdout as above) using a 256 bit AES cipher in CBC mode. There are ...



Top 50 recent answers are included