Skip to main content

Linux Tip - Rename set of files

To rename a set of files to a name starting with a particular pattern (here the pattern is taken to be to start the filename with "MyFile_"

files = `ls -1`;for file in $files; do mv $file MyFile_$file ; done


Dissection:


  1. ls -1
    • ls is the command in linux to list the files in the present directory
    • The parameter -1 will list one file a line
    • "files" is a variable which has the list of all the files listed by the command ls -1

  2. files = `ls -1`
    • save the result of ls -1 to a variable called files
    • Remember to put the command inside a pair of back ticks ` (the key is generally found just before the key "1" in the keyboard)
    • Significance of ` (backtick)

  3. for file in $files
    • Loop through each file name available in the variable files

  4. do mv $file MyFile_$file; done (The do - done loop)
    • Executes the command given after do
    • End the do with a done


Comments

Popular posts from this blog

Start with flask

1. Install python 2. Python comes with pip. Else install pip 3. pip install Flask 4. Create a file flaskFirst.py from flask import Flask app = Flask(__name__) @app.route('/') def index():     return 'Index Page' 3. Go to the path where the flaskFirst.py is present 4. export FLASK_APP=flaskFirst.py 5. flask run

Save Widows remote desktop credentials

First, START > All Programs > Accessories > Remote Desktop Connection Type in the computer name and clock OPTIONS Check off the box that says save credentials Now connect, and you will be prompted for your username/password. Enter them. Now you should be connected to the remote computer. Close out of the remote session. Method 1 Create a .bat file that has the following command: START mstsc.exe /v: & exit Run the .bat file and the remote desktop session should open and submit your saved credetials automatically. Method 2 Type mstsc -v it will login without asking credentials. Method 3 Save the session as a .rdp file (e.g: myRemoteMachine.rdp) and Double click the rdp file to open the remote desktop session without asking for credentials.