Tag Info

Hot answers tagged

31

That program probably resolves the path to that file from $HOME/.config/myprogram. So you could tell it your home directory is elsewhere, like: HOME=/nowhere your-program Now, maybe your-program needs some other resource in your home directory. If you know which they are, you can prepare a fake home for your-program with links to the resource it needs in ...


28

If all else fails, write a wrapper library that you will inject using LD_PRELOAD so that the call to open("/home/you/my-program/config.interactive") is intercepted but any other will pass through. This works for any type of program, even shell scripts, since it will filter system calls. extern int errno; int open(const char *pathname, int flags) { char ...


20

"Everything is a file" is a bit glib. "Everything appears somewhere in the filesystem" is closer to the mark, and even then, it's more an ideal than a law of system design. For example, Unix domain sockets are not files, but they do appear in the filesystem. You can ls -l a domain socket to display its attributes, cat data to/from one, modify its access ...


14

tail +1f file I tested it on Ubuntu with the LibreOffice source tarball while wget was downloading it: tail +1f libreoffice-4.2.5.2.tar.xz | tar -tvJf - It also works on Solaris 10, RHEL3, AIX 5 and Busybox 1.22.1 in my Android phone (use tail +1 -f file with Busybox).


10

The problem is that cat is not aware that the file is still being appended. As soon as cat encounters the (current) end of the file it exits. You have to make wget write to a pipe (or FIFO) in order to avoid this. wget -O - http://... | tar -xjf -


8

There are a number of problems with trying to enforce this "after the fact" using a cron job or similar: Race condition. Regardless of which method you use, if you have some program or some code that will be looking through the directory and may pick up and use files you don't want it to interact with, the only way to actually prevent it from doing that is ...


8

mimeopen -a 'picture.jpg' This is what you need It will give you output like this Please choose an application 1) Shotwell Viewer (shotwell-viewer) 2) Firefox Web Browser (firefox) 3) Image Viewer (eog)


7

From man page of file command, file command actually performs 3 tests on determining the file type. First test The filesystem tests are based on examining the return from a stat(2) system call. Second test The magic number tests are used to check for files with data in particular fixed formats. Third test The language tests ...


7

Use recode, e.g.: recode /cr file Note: the fact that you can see the contents in the terminal with cat file is that the Mac end-of-line is CR, which puts the cursor at the beginning of the line without going to the next line, so that everything gets overwritten.


6

Instead of redirecting to a file you can redirect to a command using: print "something" | "tee file1.txt file2.txt" The first time you use that |, awk spawns the command, and the next time it reuses the same command, so it doesn't start a new tee each time you do that and doesn't overwrite the files (you need to call close("tee file1.txt file2.txt") if ...


6

You can not do it with awk. Using tee, you can do something like this: $ awk '{print ID[i]" "Value[i]" "TS1[i]" "TS2[i]}' file | tee out1 out2 Using tee -a if you want to append instead of override existed files. If you don't want to print the whole output, you can try: awk ' BEGIN {outfile["a.txt"];outfile["b.txt"]} { for (file in outfile) { ...


6

I was able reproduce this both on OS X 10.6.8 and OpenBSD 5.5-current. Printing out debug information using file -D tmp, it turns out that your text file fails roughly 2000 tests before file(1) recognizes the Pascal keyword record and decides that it must be a Pascal program text. A minimal working example can be obtained as follows: $ echo record > ...


5

He's saying it's bound by a 64-bit type, which has a maximum value of (2 ^ 64) - 1 unsigned, or (2 ^ 63) - 1 signed (1 bit holds the sign, +/-). The type is not FILE; it's what the implementation uses to track the offset into the file, namely off_t, which is a typedef for a signed 64-bit type.1 (2 ^ 63) - 1 = 9223372036854775807. If a terabyte is 1000 ^ ...


5

-t lists the file's modification time, which is the last time the file's content was modified (unless the modification time was explicitly set afterwards). -c lists the file's inode change time, which is the last time the file's metadata was changed (ownership, permissions, etc.) or the file was moved. Most unix systems do not track the creation date of a ...


4

Maybe you can use the --keep-going (-k) option of file. It writes out more matching formats. Related man page description of this option: Don't stop at the first match, keep going. Subsequent matches will be have the string ‘\012- ’ prepended. (If you want a newline, see the -r option.) The magic pattern with the highest strength ...


3

if created and not touched since the user creation you can use the .bash_logout file to determine the date. As root run: ls -l /home/<username>/.bash_logout OR, If the user has a home directory, you can check that directories creation date: ls -ld /home/username/ to get only the date you can use awk: ls -ld /home/username/ | awk '{ print ...


3

Stolen (with a minor edit) from Gilles post here find <DIR> -depth -type d -exec rename -n 's!/([^/]*/?)$!\U/$1!' {} +


3

@gniourf_gniourf has the right idea: set -o errexit -o nounset cd ~/myfolder for file in *.txt do dir="${file%.txt}" mkdir -- "$dir" mv -- "$file" "$dir" done This should be POSIX compliant. It is not re-entrant. It will not work if you have any two files named something.txt and something.txt.txt.


3

You can use strace for this: strace -f -e trace=file command args... strace traces system calls and prints a description of them to standard error as they occur. The -f option tells it to track child processes and threads as well. -e lets you modify the calls it will track: -e trace=file will log every use of open, unlink, etc, but no non-file actions. ...


3

This would be it. Just some style issue with the extra comma at the end of each line. awk ' BEGIN{ FS=","; ORS="" } { # read line from secondary file getline aux < "file2" split(aux,f2,",") # print current line number print NR" " # process each field in current line for(i=1; i<=NF; i++) { ...


3

I once posted a pretty in-depth look at NTFS file-streams as related to the linux ntfs-3g driver due to a similar issue on a different question. I remembered it, and - guessing that your problem was also on an NTFS partition - I posted this comment here: If it's NTFS I suspect this. This can occur if a file's basic permissions are modified as you end up ...


3

You should be able to use tr, but not as specified on the page your link points to as that includes the removal of newline and carriage return. What you should do is: tr -d " \t" < infile.txt > outfile.txt


3

You can pass the [[:blank:]] character class to tr to delete spaces and tabs but retain newlines <file tr -d '[[:blank:]]'


3

There's no foolproof way to tell. However, for log files, the change time (as opposed to the modification time) which you see in the output of stat may be the time at which the compressed file was created, because the filesystem attributes of these compressed files are rarely modified after their creation. For .gz files which were not created by compressing ...


3

Without the ability to use sudo your options become limited to essentially 2. Method #1 You can either put the users into the same Unix group (/etc/group) so that they're able to access the same files & directories. Example $ more /etc/group somegroup:x:1001:adminuser,nobody You then need to set the parent directory that contains this file like ...


3

Use: mimeopen -a 0001.jpg -a will first Ask you to choose, not run it. Please choose an application 1) Wine Internet Explorer (wine-extension-jfif) 2) Wine Internet Explorer (wine-extension-jpe) 3) Firefox Web Browser (firefox) 4) Luminance HDR (luminance-hdr) 5) ImageMagick (display) (display.im6) 6) Image Viewer (eog) 7) Shutter (shutter) 8) ...


3

Yes, close can block: If O_NONBLOCK is not set and there have been no signals posted for the STREAM, and if there is data on the module's write queue, close() shall wait for an unspecified time (for each module and driver) for any output to drain before dismantling the STREAM. And: If fildes refers to a socket, close() shall cause the socket to be ...


3

You have to quote or escape the filename. In Bash (the default shell in most distros), you can either use quote marks to enclose the entire name, or a backslash to escape the one space. rm "my file" rm my\ file


3

You need to quote file name: rm 'my file' my_file or escape space character: rm my\ file my_file


2

You can do this with sed - but without a clearer idea of your input, I don't know how to demonstrate it specifically. Still, here is a generic example: seq 10 | sed -e '/1/w ./onesfile.txt' -e '/3/w threesfile.txt' -e d That writes only the lines containing a 1 to the onesfile.txt and otherwise for 3 - everything else is deleted. This is a very basic ...



Only top voted, non community-wiki answers of a minimum length are eligible