Tag Info

New answers tagged

2

Put this alias in your ~/.bashrc: alias swap='temp=$(mktemp); mv -- "$1" "$temp"; mv -- "$2" "$1"; mv "$temp" "$2"; rm "$temp"' Usage: swap file1 file2


2

I'm not sure you will like this answer, but, in my experience too, using PTP has always caused a high WTF/min. Presumably the camera itself restricts writing in the root folder, or something equally sensical. I would suggest getting your hands on a CompactFlash reader, mounting the filesystem directly, and using that type of access to copy your firmware ...


0

Based on @DigitalTrauma answer, this is what worked for me at last: size=$(stat -c %s file) dd bs=2 if=file skip=1 seek=0 conv=notrunc count=511 of=file dd if=file ibs=1024 skip=1 of=file conv=notrunc obs=1022 seek=1 truncate file $(( size - 2 )) Removing the first two bytes is done over 2 dd steps to speed things up and truncate is a small utility to ...


2

As one who has worked in a multitude of ?nix environments, I have had to write in a wide variety of shells. Believe it or not, across platforms, the shells are not the same. So if you maintain your personal library in multiple shells (when necessary) it is very helpful to use extensions to ID the shells. That way when you move to another platform and the ...


0

First of all, cat /etc/group only shows the groups created in the system. If you want to know which groups linuxsir belongs to, you need to use this command groups linuxsir. The result of ls -lsays: -rw-r--r-- 1 linuxsir root 1549 Feb 23 19:16 test.txt It means: user linuxsir is owner and can read and write on test.txt group root can only read Anyone ...


1

I think this should work: $ # Create test file $ echo "Hello, World" > h.data $ $ # Move contents up by 2 bytes $ # Note if= and of= are the same for in-place editing $ dd bs=2 if=h.data skip=1 seek=0 conv=notrunc of=h.data 5+1 records in 5+1 records out 11 bytes (11 B) copied, 0.000598796 s, 18.4 kB/s $ $ # Note 11 bytes were moved above $ # ...


1

Something like this should work directory=$(date +%Y-%m-%d)-scriptbackup #create if it doesn't exist mkdir -p "$directory" #find and copy #replace "." with the directory #where you want to search for the files, #if it isn't the same as the current directory find . -name '*.sh' -exec cp '{}' "$directory" ';' tar -cvzf "${directory}.tar.gz" "$directory"


2

There is difference between renaiming and moving to somewhere. In the case easyest way (in modern bash) is loop through all files: for f in *.* do d=${f::1}/${f:1:1} [ -d "$d" ] || mkdir -p "$d" mv "$f" "$d" done


1

You cannot "specify" a file type. A file is like a container containing stuff. That can be ASCII, binary or whatever. The utillity file just looks into it and "guesses" (with a pattern file called magic) whats inside. You can only change the output of the file utillity by changing the file content to something that file guesses as HTML for example. If the ...


3

A hard link means you simply add a second name for exactly the same file. Afterwards you cannot decide which name was first. File names do not have a file type or content-type like text/html. The content type is something you web server makes up. It usually does so by looking at the extension of the file name. Have a look at the documentation of your web ...


0

cd parent_dir && set -- */ && for dir do [ -L "$dir" ] && continue mv -i -- "$dir"* "$dir"..?* "$dir".[!.]* rmdir -- "$dir" done


2

If you are in the child then: Using bash shell, shopt -s dotglob mv -t .. * rmdir $(pwd) If your mv does not have -t then: shopt -s dotglob mv * .. rmdir $(pwd)


1

Implementing @Izkata's suggestion using inotifywait with paced event response to keep the rsyncs down to at most 1 every 5 minutes while still responding quickly to initial changes: #!/bin/sh # usage: whateveryouwanttotcallthis "$directorytowatch" rsync args here cd "$1" || { echo "${0##*/}: can't cd to $1"; exit 1; } shift rsync -nq "$@" || { echo "rsync ...


1

You are missing -n switch of command. You have to type: unix2dos -n /path/to/filename_unix.txt /path/to/filename_dos.txt As you typed it I think unix2dos is looking for two files to convert. So now your filename_unix.txt should be converted to dos.


3

The nobody user is a pseudo user in many Unixes and Linux distributions. According to the Linux Standard Base, the nobody user and its group are an optional mnemonic user and group. That user is meant to represent the user with the least permissions on the system. In the best case that user and its group are not assigned to any file or directory (as owner). ...


1

The user who can login as nobody can change these files, but normally the system is setup so this is not possible. On my debian based system the entry in the /etc/password file is: nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin and /usr/sbin/nologin gives: This account is currently not available. You can only change this as user root, as ...


0

As @Gilles says, since du counts only the first of all hardlinks pointing to the same inode it encounters, you can give it directories in a row: $ du -hc --max-depth=0 dirA dirB 29G /hourly.1 1G /hourly.2 30G total I.e. any file in 'hourly.2' referencing an inode (aka "real" file) already referenced in 'hourly.1', will not be counted.


0

find -name '*.jpg' -print0 folder | grep -zZ -vf name.log | xargs -0 COMMAND replace COMMAND by ls -l and if you like it by rm


2

First of all: this is your computer, so you can do anything with it that you want, so the commands to move it there are at the end of this rant. ;-) However, the application is exactly where it's supposed to be according to the File Hierarchy Standard and other applications that depend on this one will expect it there. And it doesn't matter whether you're ...


1

This file has no extended attributes (actually ACLs), or more precisely, what you see in the owner@, group@ and everyone@ lines are the default ACLs for a 0700 file. Should you really want to remove for all users outside the owner even the ability to know the attributes of the file itself, you might at your own risks use these (untested on that file) ...


2

You could use what DevNull suggested which rsyncs periodically. Personally I would use inotify. It is a nifty tool that you can give a folder to watch. It sets up watches and notifies you whenever a filesystem change occurs. You could then trigger an rsync based on the trigger from inotify. For the specific case at the end you talk about, you can use the ...


4

Per your bonus question, add the following line below the rsync command in the shell script I provided below. I wrote this in the comment but I'll officially add it to my answer here: find /auto/std2/nat2/B -name '*.zip' -exec sh -c 'unzip -d `dirname {}` {}' ';' This will handle unzipping all the zip files that are copied via rsync from folder ...


0

This is really easy w/ pax. It has a notion of a -substitution option which can change filenames as they are written. You can specify more than one -substitution argument as well. And, most relevant here, is that selected members only have as many -substitution arguments applied as are necessary to successfully make one match, but any substitution which ...


2

This is fairly easy in Python with os.walk. Warning, untested code. I assume that the list of names contains one name per line with #!/usr/bin/python2 import os names_file = open('names.log') names = set(line.rstrip('\n') for line in names_file.readlines()) names_file.close() for root, dirs, files in os.walk('/path/to/top/directory'): for name in ...


-1

If you will satisfy with bash I'd like to offer following algorithm (it could be realized on any scripting lanuage): Build list of present files: find /path_to_folder -name "*.jpg" -fprint files.tmp Sortfiles.tmp and name.log than compare its by comm -23 files.tmp name.log Pass the list of files unique for files.tmp to rm command Be aware with path of ...


0

You could try using sed : sed -rn ':a;/^([^~]*~){13}[^~]*$/!{N;s/\n//;ba};p' yourfile.tsv What it does The script has three parts separated by a ;: :a defines a label we can branch to /^([^~]*~){13}[^~]*$/!{N;s/\n//;ba} searches for a complete column /^([^~]*~){13}[^~]*$/ looks for a line with exactly 14 fields (0 or more occurrences of anything that ...


7

According to modify dates you might have some process running which creates again files and dirs you just deleted.


2

You can use the command stat to see more metadata of the file/directory.


1

The OS has permissions on the directories and if they don't permit a user to create anything in /etc it would be a security hole if some other mechanism would have the OS open other files than it thinks it is doing. (If the user has the permissions there is no need to fool the OS, then she can just change the files). That permissions on /etc are normally ...


0

The best answer to my own question is found in the answer to another post: vim: create file with +x bit. That makes this question essentially a duplicate. I think I'll delete this question unless someone sees a reason to keep it.


2

If you automate things with scripts and make scripts on a regular basis, you should automate the script creation...with a script. So instead of calling: vi some_new_program.py you should have a script newpy: #!/bin/bash echo '#!/usr/bin/env python' > "$1" echo '# coding: utf-8' >> "$1" echo '' >> "$1" chmod +x "$1" vi +3 "$1" Of course ...


0

Here is the output of iotop after killing crashplan. What is this 'rsync' process ? I am not running any rsync on the machine. Looks like 'updatedb' and 'rsynch' are using up all the IO.. Total DISK READ: 124.78 K/s | Total DISK WRITE: 0.00 B/s TID PRIO USER DISK READ DISK WRITE SWAPIN IO> COMMAND 20772 be/7 root 14.68 K/s 7.34 ...


0

Btrfs FAQ - I cannot delete an empty directory: First case, if you get: rmdir: failed to remove ‘emptydir’: Operation not permitted then this is probably because "emptydir" is actually a subvolume. You can check whether this is the case with: btrfs subvolume list -a /mountpoint To delete the subvolume you'll have to run: btrfs ...


0

You can reduce the risk of a persistent exploit by making sure that the service is not able to create an executable file anywhere. For that, make sure that all the filesystems that the service can access meet at least one of the following conditions: mounted read-only mounted with the noexec option contains no directory that is writable by the service ...


7

Use -- to distinguish between options which start from - and filename or prepend file with ./. The safest is to use both: rm -- './-C'


0

You can use an ACL to deny all users write and execute permissions and then explicitly allow only the service account user to only have the full rwx. http://linux.die.net/man/1/setfacl


0

As i can see there is no write permission to group & others, So they cant create any file/directory here. you just need to make sure that if you remove write permission from root, what will happen?


2

Under Linux, you can use the inotify kernel subsystem to efficiently wait for the appearance of a file in a directory: while read i; do if [ "$i" = sleep.txt ]; then break; fi; done \ < <(inotifywait -e create,open --format '%f' --quiet /tmp --monitor) # script execution continues ... (assuming Bash for the <() output redirection syntax) The ...


2

Just put your test in the while loop: while [ ! -f /tmp/sleep.txt ]; do sleep 1; done # next command


0

BSD's (Mac OS X's) stat has a different format argument flag, and different field specifiers. From man stat(1): -f format: Display information using the specified format. See the FORMATS section for a description of valid formats. ... the FORMATS section ... z: The size of file in bytes. So all together now: stat -f%z myfile1.txt


1

This might help some readers: In Windows, an older, little freeware program -- Third Dir -- does exactly what's being asked for here. It's no longer available via the developer, Robert Vašíček. But I'm sure it can be found via some repositories online. Here's the developer's description, which remains on his site: Third Dir: An unusual ...


0

If you are running into the limit, rearrange. Instead of: gzip file do: gzip < file > file.gz Works just fine.


1

Run the command pkill pantheon-files in the terminal The pkill command sends a signal to terminate the process with name pantheon-files; a process is a running instance of a program. Reopen the file manager by clicking on the icon on the dock or from the application menu. By clicking on the icon, a new process is started for the program.


3

With zsh: for d (subdir*(/)) mixb $d/*.(dat|d01)([1]) The bash equivalent would be something like: shopt -s nullglob extglob for d in subdir*/; do [ -L "${d%/}" ] && continue set -- "$d"*.@(dat|d01) [ "$#" -eq 0 ] || mixb "$1" done


0

which program do you use to download? If the program doesn't have hard permission for new files compiled in, you can simply set the environments umask before starting the program (in the same env / shell). With bash there is a "umask" command, try 'help umask' in bash. e.g. umask 0000; wget htpp://


1

the permission to move/rename a dir, comes from the permission of the ".." dir (containing dir), not from the dir itself. Simple testcase $ mkdir testdir/subdir -p $ chmod -w testdir $ mv testdir/subdir testdir/othersub mv: das Verschieben von »testdir/subdir“ nach »testdir/othersub“ ist nicht möglich: Keine Berechtigung ==> no permission


3

To get all the info provided by ls -l for a single file or folder, use the -d option and specify the file: ls -ld filename


2

If your intention is to do something depending on the file permission then in some cases you can consider simple test (aka [ or [[) conditional statement: -r file exists and read permission is granted -w file exists and write permission is granted -x exists and execute permission is granted For example: [ -w file ] && echo foo >> file


1

As "permissions" doesn't just cover octal unix permissions on modern Linux systems, I'd like to elaborate a little: Apart from stat -c %a file @vinc17 suggested, there's stat -c %C file for the SELinux context on RHEL Systems, and getfacl file for volumes using ACLs. namei -m /path/to/file might be helpful for finding out all octal permissions leading down ...


4

To just get the mode: stat -c %a file (where file can also be a directory). Note: this is with the stat command from the GNU Coreutils. Otherwise the solution is system dependent.



Top 50 recent answers are included